I want to know why ~Test2 and ~Test1 are not called in this case:
public class Test1
{
public:
Test1() { Console::WriteLine("Test1\n"); }
virtual ~Test1() { Console::WriteLine("~Test1\n"); }
};
class Test2 : public Test1
{
public:
Test2() { Console::WriteLine("Test2\n"); }
virtual ~Test2() { Console::WriteLine("~Test2\n"); }
};
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Testing destructors");
//Test1* t1 = new Test2(); // Test2 is cast as Test1
//delete t1;
//Console::ReadKey();
//Console::WriteLine(L"Now void*:");
void* v = new Test2();
delete v;
Console::ReadKey();
return 0;
}
Is this a
- A rule that requires all compilers act this way?
- A bug in C++ compiler implementation?
- A behavior left undefined and so it varies from compiler to compiler?