"This" reference?
C / C++ / MFC
3
Posts
3
Posters
0
Views
1
Watching
-
this
is a pointer to the class in which the current function is a member. - Anders Money talks, but all mine ever says is "Goodbye!" -
Here are some examples of when this is used: 1. Sometimes you will see it as a function parameter. For example, registering a callback:
Server::RegisterCallback( this );
2. It is used for a lot of overloaded operators:Vector const & operator +( Vector const & b ) { ... return *this; }
3. When overloading operator= you must make sure that the source is not the same as the destination:Vector const & operator =( Vector const & b ) { if ( this != &b ) { ... } return *this; }
You will probably never see "this->" because there is never a need for it -- it is automatic.