Thread: DLL boundaries and delete.

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    132

    DLL boundaries and delete.

    Hello,
    I'm having a problem here obviously.. I have a dll and an application using it, which needs to insert an object instance in a list in the dll through a function like:

    Code:
    IVolatileResource* CResourceManager::AddObject (IVolatileResource *pObj)
    The IVolatileResource class is a base class which my objects derive from. Now the problem is that if i allocate the object IN that function, everything is ok, but if I allocate it outside the dll, using AddObject (new CMyObject), where CMyObject derives from volatileresource class, when I delete the object created in the manager's destructor, the debugger says that it cannot access that memory in the heap. It is important that I pass the object that way. Is there any workaround?
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

  2. #2
    Registered User
    Join Date
    Jun 2002
    Posts
    132
    Nevermind, I found it, the destructor of the VolatileResource class needed to be virtual. But why is that needed? (The class is abstract)
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Making the destructor virtual gives the base class destructor a chance to run when destructing a derived class.
    This also has other side effects within a multi-module address space depending on how things are defined and exported. You don't have to worry about most of these side effects as long as you aren't mixing the CRT's being used by each module..

    gg

Popular pages Recent additions subscribe to a feed