Double destructor?

  • Thread starter Thread starter Steven Cool
  • Start date Start date
S

Steven Cool

I have a c++ dll which i use in c# classes with the help of a wrapper
class.
In that wrapper class I have a destructor but I also have a destructor
in my c++ class. It looks like thios

----------------
c++ class:

class Object
{
Object::Object(){...}

Object::~Object(){...}
}

-------------------
Wrapper class:

class WrapperObject:
{
private Object o;

WrapperObject::WrapperObject{...}

WrapperObject::~WrapperObject{...}
}

-----------------------


When I run the code, I sometimes (not always) get this error:

HEAP[CanTracer.exe]: Heap block at 07BC9C08 modified at 07BC9BFB past
requested size of ffffffeb

Could it be that this 'double destructor' is the reason?
How to solve it on a goor manner?
 
I have a c++ dll which i use in c# classes with the help of a wrapper
class.
In that wrapper class I have a destructor but I also have a destructor
in my c++ class. It looks like thios

----------------
c++ class:

class Object
{
Object::Object(){...}

Object::~Object(){...}
}

The above (typos removed) is generally bad practice. If you write a
class that needs a destructor, that generally means that the copy
constructor and assignment operator need attention. Typically you
either implement them, or make them private and don't implement them.
e.g.

class Object
{
public:
Object(){...}
~Object(){...}
private:
Object(Object const&); //no definition
Object& operator=(Object const&); //no definition
};

This is generally called the "Rule of 3".
-------------------
Wrapper class:

class WrapperObject:
{
private Object o;

WrapperObject::WrapperObject{...}

WrapperObject::~WrapperObject{...}
}

-----------------------


When I run the code, I sometimes (not always) get this error:

HEAP[CanTracer.exe]: Heap block at 07BC9C08 modified at 07BC9BFB past
requested size of ffffffeb

Could it be that this 'double destructor' is the reason?

I suspect you are creating an incorrect copy of your Object, since it
isn't currently copyable. Both the copy and the original have their
destructors run, hence your problem.

Tom
 
Back
Top