M
Maxim Yegorushkin
The following code:
#include <iostream>
class base
{
private:
virtual ~base()
{
std::cout << "virtual ~base()\n";
}
};
class derived : public base // must result in a compile time error
{
// does result in a compile time error when uncommented
//~derived() {}
};
int main()
{
// does result in a compile time error when uncommented
//derived dd;
derived* d = new derived;
delete d;
}
Produces no error when compiled thought it must. It only produces 2
warnings:
warning C4624: 'derived' : destructor could not be generated because a
base class destructor is inaccessible
warning C4527: instances of class 'derived' can never be destroyed -
user-defined destructor required
The second warning is false - the code does create an instance of derived
and what much worse it does destroy it. At runtime it seems like base's
destructor does not get called.
#include <iostream>
class base
{
private:
virtual ~base()
{
std::cout << "virtual ~base()\n";
}
};
class derived : public base // must result in a compile time error
{
// does result in a compile time error when uncommented
//~derived() {}
};
int main()
{
// does result in a compile time error when uncommented
//derived dd;
derived* d = new derived;
delete d;
}
Produces no error when compiled thought it must. It only produces 2
warnings:
warning C4624: 'derived' : destructor could not be generated because a
base class destructor is inaccessible
warning C4527: instances of class 'derived' can never be destroyed -
user-defined destructor required
The second warning is false - the code does create an instance of derived
and what much worse it does destroy it. At runtime it seems like base's
destructor does not get called.