i am reading a c++ book and i come a long with a chapter thats about the this-> poiter what exactly this pointer does can anyone cleanyl explain to me thx.
i am reading a c++ book and i come a long with a chapter thats about the this-> poiter what exactly this pointer does can anyone cleanyl explain to me thx.
C++ Makes you Feel Better
"Gravity connot be held reponsible for people falling in love"--Albert Einstein
it's a pointer to yourself so you can tell other objects where you are.
can you explain this a little bit detailed thx.
C++ Makes you Feel Better
"Gravity connot be held reponsible for people falling in love"--Albert Einstein
It seems like there just HAS to be a FAQ on this. hmmm. Oh well. Here goes.
simplest terms... from any method in a class, "this" means a pointer to the object you are in. You can use it like you would use any pointer. You would most likely use it to leave a link to yourself somewhere. For instance if you wish to hand your pointer over to someone like in a list.
See?Code:void MyClass::dosomething() { g_list.AddToList(this); }
also very useful for overloaded assignment operators, eg
Code:Vector3d& Vector3d::operator = ( const Vector3d& rvalue ) { for( int i = 0; i < 3; i++ ) { triple[ i ] = rvalue.triple[ i ]; } return *this; }
let's not confuse the newbie with returning a reference in an overloaded operator.