In C++, an object refers to itself via this.
But how does an instance of an inner class refer to the instance of its enclosing class?
class Zoo
{
class Bear
{
void runAway()
{
EscapeService::helpEscapeFrom (
this, /* the Bear */
??? /* I need a pointer to the Bear's Zoo here */);
}
};
};
EDIT
My understanding of how non-static inner classes work is that Bear can access the members of its Zoo, therefore it has an implicit pointer to Zoo. I don’t want to access the members in this case; I’m trying to get that implicit pointer.
Unlike Java, inner classes in C++ do not have an implicit reference to an instance of their enclosing class.
You can simulate this by passing an instance, there are two ways :
pass to the method :
pass to the constructor :