If we dont have virtual constructors then why we have virtual destructors? Can constructors also be virtual?
A* a = new B;
[B
inherits
from A
], and you later delete a;
- the compiler has no way of
knowing a
is a B
[in the general case], and will invoke A
's
destructor - if it wasn't virtual, and you might get a memory leak,
or other faults.B
's destructor is
invoked, since a B
object is being destroyed.