What does "this" mean

This is a discussion on What does "this" mean within the C++ Programming forums, part of the General Programming Boards category; I am reading a C++ tutorial book and it had this Code: m_pGameEngine = this ; what does "this" mean?...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    151

    What does "this" mean

    I am reading a C++ tutorial book and it had this

    Code:
    m_pGameEngine = this;
    what does "this" mean?

  2. #2
    Registered User
    Join Date
    Jan 2009
    Posts
    103
    can you give us a little bit of context? (the full code, or the whole class or something?)

  3. #3
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    "this" is a reference to the object the code is currently running in. So if you're writing a function that's a member of the "GameEngine" class, "this" refers to the instance of GameEngine that the function was called on.

    Code:
        myGameEngine.doSomething(); // in the code for the doSomething() function, 'this' would be the 'myGameEngine'
    It's often useful when you might be dealing with two instances of the same class and you need to be unambiguous, or just for anytime you want to pass that specific instance somewhere else.

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    151
    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. "this" keyword question
    By Toonzaka in forum C++ Programming
    Replies: 4
    Last Post: 08-12-2010, 10:32 AM
  2. Replies: 1
    Last Post: 10-29-2009, 08:00 PM
  3. another way for "this" pointer
    By dukebdx12 in forum C++ Programming
    Replies: 12
    Last Post: 06-23-2008, 11:52 PM
  4. Passing "this" as function parameter
    By pgavigan in forum C++ Programming
    Replies: 15
    Last Post: 07-13-2007, 11:06 AM
  5. quick question concerning "this"
    By HIM in forum C++ Programming
    Replies: 4
    Last Post: 11-04-2006, 07:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21