I know about the use of private (and, of course, public) destructors.
I also know about using a protected destructor in a derived class:
Use a protected destructor to prevent the destruction of a derived object using a base class pointer
But I tried to run the following code and it will not 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(); bf(); 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 from inside f (), it will work. So why is the name d'or?
c ++ inheritance oop c ++ 11 destructor
Shookie
source share