Thread: what exacly (this->) mean?

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    106

    what exacly (this->) mean?

    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

  2. #2
    Registered User
    Join Date
    Jul 2002
    Posts
    273
    it's a pointer to yourself so you can tell other objects where you are.

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    106
    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

  4. #4
    Registered User
    Join Date
    Jul 2002
    Posts
    273
    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.

    Code:
    void MyClass::dosomething()
       {
       g_list.AddToList(this);
       }
    See?

  5. #5
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    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;
    }

  6. #6
    Registered User
    Join Date
    Jul 2002
    Posts
    273
    let's not confuse the newbie with returning a reference in an overloaded operator.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. small -> big -> bigger -> bigger than bigger -> ?
    By happyclown in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 03-11-2009, 12:12 PM
  2. Dev-C++ -> Tools - > Editor -> Syntax
    By Yuri2 in forum C++ Programming
    Replies: 19
    Last Post: 07-03-2006, 07:48 AM
  3. > > > Urgent Help < < <
    By CodeCypher in forum C Programming
    Replies: 2
    Last Post: 01-31-2006, 02:06 PM
  4. Replies: 4
    Last Post: 01-03-2006, 03:02 AM