I'm aware of the uses of private (and of course public) destructors.
I'm also aware of the uses of a protected destructor in a derived class:
Use a protected destructor to prevent the destruction of a derived object via a base-class pointer
But I've tried running the following code and it won't compile:
struct A{
int i;
A() { i = 0;}
protected: ~A(){}
};
struct B: public A{
A* a;
B(){ a = new A();}
void f(){ delete a; }
};
int main()
{
B b= B();
b.f();
return 0;
}
I get:
void B::f()':
main.cpp:9:16: error: 'A::~A()' is protected
What am I missing?
If I called a protected method in A from inside f() it would work. So why is calling the d'tor different?
*this
in a derived class' member function. – dyp