C
ct
Hi,
Here is my problem: I need to be able to call a virtual method when an
object is deleted.
class A
{
public:
virtual ~A();
void virtual DestroyRespond();
};
class B : public A
{
public:
virtual ~B();
void virtual DestroyRespond();
};
A::~A()
{
DestroyRespond();
}
void A:
estroyRespond()
{
printf("destruction of A\n");
}
B::~B()
{
}
void B:
estroyRespond()
{
printf("destruction of B\n");
A:
estroyRespond();
}
int main(int argc, char* argv[])
{
B *b = new B();
delete b;
}
obviously this will never work, the virtual method of object B will
never get called on the destruction of B.
Is there a way ""overloading the operator delete"" for example that will
solve my problem.
here is one of the limitation cannot call A:
perator delete b; i need
this to be transparent as part of a framework. I also know that with a
smart_pointer this could be solve but i also neet the contruction of B
to be standart.
the framework needs to be standart
B *b = new B();
delete b;
the ouput will need to be
destruction of B
destruction of A
thanks.
Here is my problem: I need to be able to call a virtual method when an
object is deleted.
class A
{
public:
virtual ~A();
void virtual DestroyRespond();
};
class B : public A
{
public:
virtual ~B();
void virtual DestroyRespond();
};
A::~A()
{
DestroyRespond();
}
void A:
{
printf("destruction of A\n");
}
B::~B()
{
}
void B:
{
printf("destruction of B\n");
A:
}
int main(int argc, char* argv[])
{
B *b = new B();
delete b;
}
obviously this will never work, the virtual method of object B will
never get called on the destruction of B.
Is there a way ""overloading the operator delete"" for example that will
solve my problem.
here is one of the limitation cannot call A:
this to be transparent as part of a framework. I also know that with a
smart_pointer this could be solve but i also neet the contruction of B
to be standart.
the framework needs to be standart
B *b = new B();
delete b;
the ouput will need to be
destruction of B
destruction of A
thanks.