consider the following code :
struct A {
virtual void foo() {}
virtual ~A() = 0;
};
struct B :public A
{
virtual void foo() {};
};
A::~A() {};
int main()
{
A * a = new B();
a->foo();
}
it works perfectly fine. but now consider the second code where we need to declare our classes locally inside a function as:
void foo()
{
struct A {
virtual void foo() {}
virtual ~A() = 0;
};
struct B :public A
{
virtual void foo() {};
};
A::~A() {}; //error C2352 : 'A::~A' : illegal call of non - static member function
A * a = new B();
a->foo();
}
int main()
{
foo();
}
the code dose not compile! any idea? is the any way to redefine the pure virtual destructor of the base class which is declared locally?
= 0
and provide code directly. – Bremerhaven