E
Eric
Consider the following:
class ParentClass
{
public:
void FunctionOne( void );
protected:
void FunctionTwo( void );
private:
void FunctionThree( void );
};
ParentClass::FunctionOne( void )
{
FunctionTwo();
}
ParentClass::FunctionTwo( void )
{
FunctionThree();
}
ParentClass::FunctionThree( void )
{
printf( "Executing parent class's FunctionThree\n" );
}
class ChildClass : public ParentClass
{
public:
void FunctionTwo( void );
void FunctionThree( void );
};
ChildClass::FunctionTwo( void )
{
FunctionThree();
}
ChildClass::FunctionThree( void )
{
printf( "Executing child class's FunctionThree\n" );
}
int main( int argc, char** argv )
{
ChildClass* ccPtr = new ChildClass;
ccPtr->FunctionOne();
}
There is no ChildClass::FunctionOne(), so it's actually
ParentClass::FunctionOne() that gets executed.
My question is, is the call to FunctionTwo() within FunctionOne() a
call to the parent class's FunctionTwo(), or the child class's
FunctionTwo()?
I suspect it's the former (parent class), so my question then becomes,
how do I force it to execute the child class's FunctionTwo()?
Maybe something like pass FunctionOne() the "this" pointer and then
have FunctionOne call FunctionTwo and FunctionThree using the this
pointer (i.e. "CallersThis->FunctionOne()" and
"CallersThis->FunctionTwo()")?
class ParentClass
{
public:
void FunctionOne( void );
protected:
void FunctionTwo( void );
private:
void FunctionThree( void );
};
ParentClass::FunctionOne( void )
{
FunctionTwo();
}
ParentClass::FunctionTwo( void )
{
FunctionThree();
}
ParentClass::FunctionThree( void )
{
printf( "Executing parent class's FunctionThree\n" );
}
class ChildClass : public ParentClass
{
public:
void FunctionTwo( void );
void FunctionThree( void );
};
ChildClass::FunctionTwo( void )
{
FunctionThree();
}
ChildClass::FunctionThree( void )
{
printf( "Executing child class's FunctionThree\n" );
}
int main( int argc, char** argv )
{
ChildClass* ccPtr = new ChildClass;
ccPtr->FunctionOne();
}
There is no ChildClass::FunctionOne(), so it's actually
ParentClass::FunctionOne() that gets executed.
My question is, is the call to FunctionTwo() within FunctionOne() a
call to the parent class's FunctionTwo(), or the child class's
FunctionTwo()?
I suspect it's the former (parent class), so my question then becomes,
how do I force it to execute the child class's FunctionTwo()?
Maybe something like pass FunctionOne() the "this" pointer and then
have FunctionOne call FunctionTwo and FunctionThree using the this
pointer (i.e. "CallersThis->FunctionOne()" and
"CallersThis->FunctionTwo()")?