how to use 'this' for different obj in class

This is a discussion on how to use 'this' for different obj in class within the C++ Programming forums, part of the General Programming Boards category; can anyone help me to understand how the compiler knows which objects we are refering to in class. let say ...

  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,185
    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, 05:30 AM
  3. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 02:03 AM
  4. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 02:30 PM

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