Thread: is thispointer is a part of an object

  1. #1
    Registered User
    Join Date
    Mar 2008
    New York

    is thispointer is a part of an object


    can we say "this" pointer is a part of the object in question or it is something created by compiler outside the object to store address of the object?
    i think it is not the part of it. also it is not considered while calculating the size of the object. so it is a pointer synthesized by compiler which is tightly associated with the object staying outside it and not exposed to the outside objects.

    correct me, if i m wrong, pls.

    Last edited by Alexpo; 10-16-2009 at 10:02 AM.

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Katy, Texas
    "this" is a reference to the instance of the object. "this", unlike other member variables, is not part of the object itself.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Waterloo, Texas
    The 'this' pointer is simply the address of the object itself. For instance, let's say you have a structure located in memory at 0x80000000, well that would be the 'this' pointer. It get's a little more complicated with multiple inheritence, since each of the base-class instances will generally contain member data that must start at a specific offset within the class, and so the base address of each inherited type will be different (eg: require a different 'this' pointer). For example:

    #include <iostream>
    typedef char pad[ 27 ];
    struct foo
    	pad unused;
    struct bar
    	pad unused;
    struct baz
    	pad unused;
    struct qux : foo, bar, baz
    {	};
    template < typename Type >
    void print( char const* name, Type const& data )
    	std::cout << "Address of " << name << " : " 
    	<< reinterpret_cast< int const* >( &data ) << std::endl;	
    int main( void )
    	qux object;	
    	print( "foo", static_cast< foo const& >( object ) );
    	print( "bar", static_cast< bar const& >( object ) );
    	print( "baz", static_cast< baz const& >( object ) );
    	print( "qux", object );
    	return 0;
    Last edited by Sebastiani; 10-16-2009 at 11:25 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. synchronization object choosing
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 03-22-2008, 04:33 AM
  2. Include Problems
    By loopshot in forum Game Programming
    Replies: 13
    Last Post: 02-17-2006, 03:22 PM
  3. Making a script language?
    By Blackroot in forum Game Programming
    Replies: 10
    Last Post: 02-16-2006, 02:22 AM
  4. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM
  5. ERRPR: Object reference not set to an instance of an object
    By blackhack in forum C++ Programming
    Replies: 1
    Last Post: 07-13-2005, 05:27 PM