Hello, I have a situation that looks like the following code:
#include <iostream>
class A
{
public:
A() { std::cout << "A created!" << std::endl; }
~A() { std::cout << "A destroyed!" << std::endl; }
virtual const char* Name() { return "A"; }
};
class B : public A
{
public:
B() { std::cout << "B created!" << std::endl; }
~B() { std::cout << "B destroyed!" << std::endl; }
const char* Name() { return "B"; }
};
int main()
{
A* a = new B();
std::cout << a->Name() << "\n";
delete a;
return 0;
}
I want B to be destroyed when A is destroyed too. Is this possible in its destructor or do I have to implement a virtual Destroy() method or something like that?