Thread: how to use 'this' for different obj in class

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    30

    Unhappy how to use 'this' for different obj in class

    can anyone help me to understand how the compiler knows which objects we are refering to in class.
    let say there are two objects with the same function methods:
    obj a;
    obj b;
    and there is a function where i need to relate this two objects.of course one of the object will be passed as argument so that's is simple.
    but how can i refer back to the other obj eg obj a?

    i kind of know we need to use this.but how?

    thanks in advance

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    If you do a.whatever(), then you are calling the member function of a, so all of a's data is right there. If you pass in b, then you will have to access elements of b using dot notation.

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    30
    thanks! i get it now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 09:10 AM
  2. Specializing class
    By Elysia in forum C++ Programming
    Replies: 6
    Last Post: 09-28-2008, 04:30 AM
  3. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  4. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM