Re: virtual constructors and distructors...
On Jun 27, 12:46 pm, Diego Martins <jose.di...@gmail.com> wrote:
On Jun 26, 7:55 am, dasjotre <dasjo...@googlemail.com> wrote:
struct Base
{
virtual ~Base()=0{}
this is a syntax error
it should be
struct Base
{
virtual ~Base()=0;};
...
Base::~Base() {}
Good point. Also why destructor can be non virtual? Is there any use
for that? I have never seen a real world scenario where destructors
shoudl not be virtual.
On the other hand, constructors can't be virtual as was already
pointed out. Except for one compiler called Borland C++ Builder. That
compiler allowed to declare virtual constructors, although the meaning
was different of what you could expect.
Normally C++ constructors can't make virtual function calls, because
the the VMT (virtual method table) is not fully built yet, leading to
subtle and unexpected bugs. In C++ Builder, you could declare your
constructors to be virtual, meaning that before executing the
constructor, the VMT would be fully built and therefore the virtual
methods would be called as appropiate.
Cheers,
Guillermo.