Object not destroyed
Jul 17, 2012 at 10:52am UTC
Hi, I have the following scenario:
The Interface header file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#ifdef WIN32
#define DLL_CALL __stdcall
#else
#define DLL_CALL
#endif
class DLLInterface {
protected :
virtual void DLL_CALL destroy() = 0;
public :
void operator delete (void * p) {
if (p) {
DLLInterface* i = static_cast <DLLInterface*>(p);
i->destroy();
}
}
};
template <class Interface>
class DLLImpl : public Interface {
public :
virtual ~DLLImpl() { }
virtual void DLL_CALL destroy() {
delete this ;
}
void operator delete (void * p) {
::operator delete (p);
}
};
struct InterfaceA
{
virtual int MethodA() = 0;
}
InterfaceA* CreateObject();
The implementation file:
1 2 3 4 5 6 7 8 9 10 11
class ImplementationA : public DLLInterface<InterfaceA>
{
int MethodA() { ... };
}
InterfaceA* CreateObjectA()
{
return new ImplementationA();
}
The user file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
class UserOfA
{
private :
InterfaceA* m_InterfaceA;
public :
UserOfA()
{
m_InterfaceA = CreateObjectA();
}
~UserOfA()
{
delete m_InterfaceA;
};
CallAMethod()
{
m_InterfaceA->MethodA();
}
}
In the above example (simplified compared to my code) when the class UserOfA is destroyed the class ImplementationA is not!
I have another 3 object with this structure and they works with no problem.
What are the causes that may prevent the ImplementationA destruction?
Tanks in advance,
Daniele.
Jul 17, 2012 at 1:43pm UTC
Found.... I forgot to derive InterfaceA from DLLInterface:
1 2 3 4
struct InterfaceA : public DLLInterface
{
virtual int MethodA() = 0;
}
Daniele.
Topic archived. No new replies allowed.