home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 18078 < prev    next >
Encoding:
Internet Message Format  |  1992-12-16  |  1.2 KB

  1. Path: sparky!uunet!mcsun!uknet!axion!newsserver!chipmunk!crt
  2. From: crt@zoo.bt.co.uk (Clive R Thompson)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: question about "this"
  5. Message-ID: <1992Dec16.115555.4233@zoo.bt.co.uk>
  6. Date: 16 Dec 92 11:55:55 GMT
  7. References: <1992Dec9.183430.13147@news.columbia.edu>
  8. Sender: news@zoo.bt.co.uk
  9. Reply-To: crt@zoo.bt.co.uk
  10. Organization: BT Laboratories
  11. Lines: 36
  12.  
  13. In article 13147@news.columbia.edu, ae2@cunixb.cc.columbia.edu (Amiran Eliashvili) writes:
  14. >
  15. >Hi all:
  16. >
  17. >
  18. >I have been reading C++ code as I am new to the language. Recently I
  19. >have run into a segment of code that I did not quite understand what
  20. >is exactly meant.
  21. >
  22. >
  23. >     String & String::operator= (const String& string)
  24. >     {
  25. >     if (this != &string)
  26. >     {
  27. >         destruct(this->d_string_p);
  28. >         this->d_string_p = init(string);
  29. >     }
  30. >     return *this;
  31. >     }
  32. >
  33. >
  34. >I am not quite sure why and what for the clause "this"is compared to
  35. >&string? Could anyone shed some light on this matter. Thanks much.
  36. >
  37.  
  38.     Simple, see below 
  39.  
  40.     String s1;
  41.  
  42.     s1 = s1;   // The test for (this != &srtring) simply detects this assignment
  43.  
  44. or looking at it the another way  s1.operator=(s1);
  45.             
  46.                     
  47.  
  48.             Clive Thompson.
  49.