C
Calvin Lai
Hi all,
I have a simple question. If I have a ClassA as base class, and ClassB
derive from it. There is a virtual function foo() in ClassA, and in Class B,
I defined a function called foo() as well (w/ or w/o declaring it as virtual
doesn't matter since the virtual is inhered, right?). Both of them have a
virtual destructor.
Now, here is the part of the code:
ClassA::foo()
{
cout << "In class A"
}
ClassB::foo()
{
cout << "In class B"
}
ClassA::~ClassA()
{
cout << "destroying A"
}
ClassB::~ClassB()
{
cout << "destroying A"
}
When deleting objectB (from ClassB), both destructors are called. However,
when calling objectB's foo, only the classB's foo is called. Why is that?
Thanks for all your help.
I have a simple question. If I have a ClassA as base class, and ClassB
derive from it. There is a virtual function foo() in ClassA, and in Class B,
I defined a function called foo() as well (w/ or w/o declaring it as virtual
doesn't matter since the virtual is inhered, right?). Both of them have a
virtual destructor.
Now, here is the part of the code:
ClassA::foo()
{
cout << "In class A"
}
ClassB::foo()
{
cout << "In class B"
}
ClassA::~ClassA()
{
cout << "destroying A"
}
ClassB::~ClassB()
{
cout << "destroying A"
}
When deleting objectB (from ClassB), both destructors are called. However,
when calling objectB's foo, only the classB's foo is called. Why is that?
Thanks for all your help.