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:
Code:
#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;
}