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.
There is no built-in mechanism to achieve this. You need to provide the pointer yourself, via constructor or some kind of SetParent function.