home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / cplus / 19807 < prev    next >
Encoding:
Text File  |  1993-01-23  |  1.8 KB  |  77 lines

  1. Path: sparky!uunet!math.fu-berlin.de!informatik.tu-muenchen.de!rz.uni-passau.de!hiwi170.rz.uni-passau.de!schmidt
  2. From: schmidt@rz.uni-passau.de (SCHMIDT GUIDO)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Friend ..Overload Assignment opertr ..
  5. Date: Sat, 23 Jan 1993 14:18:19 GMT
  6. Organization: University of Passau - Germany
  7. Lines: 65
  8. Message-ID: <schmidt.32@rz.uni-passau.de>
  9. References: <1993Jan22.075317.21062@usl.edu>
  10. NNTP-Posting-Host: hiwi170.rz.uni-passau.de
  11.  
  12. In article <1993Jan22.075317.21062@usl.edu> rks9954@usl.edu (Srinivasa Rao K) writes:
  13.  
  14.  
  15.  
  16.  
  17. > Hi C++ masters,
  18.  
  19. >       I have small question ...
  20.  
  21. >       I am writing a "string"  class which i should be able
  22. >       to use like
  23.  
  24.  
  25. >       string str1;
  26.  
  27. >       str1 = "Hello world" ;
  28.  
  29.  
  30.  
  31. >       But We canot use a friend to overload the assignment oprator.
  32.  
  33. >      So finally  I had to convince myself to use something like
  34.  
  35.  
  36. >       str1 <= "Hello world"
  37.  
  38.  
  39. >       which works.
  40.  
  41. >      Is there any way to do the first method ....
  42.  
  43. >      
  44. >      Thanks for those who spend time reading this ....
  45.  
  46.  
  47.  
  48.  
  49. >Rao.
  50.  
  51. Hello!
  52.  
  53. operator=() is something like a constructor with built in destructor. You
  54. can specify as many different constructors for one class as you like.
  55. Likewise you can do for operator=().
  56. So why not have:
  57.  
  58.     class String {
  59.         public:
  60.         ...
  61.         String& operator=( const String& aString ) { ... }
  62.         String& operator=( char * aCharPtr ) { ... }
  63.         String& operator=( const char aChar ) { ... }
  64.         ...
  65.     };
  66.  
  67. I hope this will help you.
  68.  
  69. Guido.
  70. --------------------------------------------------------------------
  71. - Guido Schmidt                                                    -
  72. - schmidt@rz.uni-passau.de                                         -
  73. - Universitaet Passau, Germany                                     -
  74. --------------------------------------------------------------------
  75.  
  76.