M
marcwentink
Say I have a class A, and a class B that inherits from A. Now A (and B)
has a virtual destructor and a virtual function F();
If I now make these statements
A* ptrA = new B;
ptrA->F();
delete ptrA
then in the statement ptrA->F(), by means of the polymorph behavior,
the F() of class B is called. But the F() of class B only. And in
delete ptrA, both destructors of class A and B are called.
Is this right? Because then the two statements behave differently.
Somehow, for a moment, I was thinking that in the call ptrA->F(), both
virtual functions of class A and B should be processed.
has a virtual destructor and a virtual function F();
If I now make these statements
A* ptrA = new B;
ptrA->F();
delete ptrA
then in the statement ptrA->F(), by means of the polymorph behavior,
the F() of class B is called. But the F() of class B only. And in
delete ptrA, both destructors of class A and B are called.
Is this right? Because then the two statements behave differently.
Somehow, for a moment, I was thinking that in the call ptrA->F(), both
virtual functions of class A and B should be processed.