this keyword

   
this keyword Object pointer in member function

  primary-expr  := this 

The this keyword can be used only in nonstatic member functions. Its value is a pointer to the target object of a member function call. If the member function is qualified (with const or volatile ), the same qualifiers apply to the type of this .

Example

 struct point {   bool operator==(const point& that) {     return  this  ->x() == that.x() &&  this  ->y() == that.y(  );   }   bool operator!=(const point& that) {     return !(*  this  == that);   }   bool write(FILE* fp) {     fwrite(static_cast<void*>(  this  ), sizeof(*  this  ), 1, fp);   } }; 

See Also

class , expression , Chapter 6

   


C++ in a Nutshell
C++ in a Nutshell
ISBN: 059600298X
EAN: 2147483647
Year: 2005
Pages: 270
Authors: Ray Lischner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net