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 :
class Zoo
{
class Bear
{
void runAway( Zoo & zoo)
{
EscapeService::helpEscapeFrom (
this, /* the Bear */
zoo );
}
};
};
pass to the constructor :
class Zoo
{
class Bear
{
Bear( Zoo & zoo_ ) : zoo( zoo_ ) {}
void runAway()
{
EscapeService::helpEscapeFrom (
this, /* the Bear */
zoo );
}
Zoo & zoo;
};
};
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…