home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!uknet!axion!newsserver!chipmunk!crt
- From: crt@zoo.bt.co.uk (Clive R Thompson)
- Newsgroups: comp.lang.c++
- Subject: Re: question about "this"
- Message-ID: <1992Dec16.115555.4233@zoo.bt.co.uk>
- Date: 16 Dec 92 11:55:55 GMT
- References: <1992Dec9.183430.13147@news.columbia.edu>
- Sender: news@zoo.bt.co.uk
- Reply-To: crt@zoo.bt.co.uk
- Organization: BT Laboratories
- Lines: 36
-
- In article 13147@news.columbia.edu, ae2@cunixb.cc.columbia.edu (Amiran Eliashvili) writes:
- >
- >Hi all:
- >
- >
- >I have been reading C++ code as I am new to the language. Recently I
- >have run into a segment of code that I did not quite understand what
- >is exactly meant.
- >
- >
- > String & String::operator= (const String& string)
- > {
- > if (this != &string)
- > {
- > destruct(this->d_string_p);
- > this->d_string_p = init(string);
- > }
- > return *this;
- > }
- >
- >
- >I am not quite sure why and what for the clause "this"is compared to
- >&string? Could anyone shed some light on this matter. Thanks much.
- >
-
- Simple, see below
-
- String s1;
-
- s1 = s1; // The test for (this != &srtring) simply detects this assignment
-
- or looking at it the another way s1.operator=(s1);
-
-
-
- Clive Thompson.
-