留个坑。
class Base
{
public:
int a = 0x55;
void destroy()
{
cout << "destroy: " << hex << this << dec << endl;
this->show();
delete this;
}
virtual void show() { cout << "Base: show" << endl; }
virtual ~Base() { cout << "Base: " << hex << this << dec << endl; }
};
class d1 : public Base
{
public:
int b = 0x66;
virtual void show() { cout << "d1: show" << endl; }
virtual ~d1() { cout << "d1: " << hex << this << dec << endl; }
};
class d2 : public d1
{
public:
int c= 0x77;
virtual void show() { cout << "d2: show" << endl; }
virtual ~d2() { cout << "d2: " << hex << this << dec << endl; }
};
int main()
{
d2* p = new d2;
cout << "d2: " << hex << p << dec << endl;
p->destroy();
return 0;
}
|