P
Philip Lee Bridson
Good Evening,
I have been writing apps in C++ for a while now but I have to admit
the below problem has stumped me - I would not consider myself an
'expert' but also I am not a novice. Any help would be appreciated.
I have a copy constructor which is defined as follows:
Object::Object(const Object& o) {
if (o != NULL) {
if (_internalObject != NULL) {
delete _internalObject;
_internalObject = NULL;
}
_message = ex.Message();
if (o.InternalObject() != NULL) {
_internalObject = new Object();
_internalObject = ex.InternalObject();
}
}
}
When I get to the line that deletes the internal object (which is a
pointer that is initialized during the constructor) I get
EXC_BAD_ACCESS. I have debugged the app and I can confirm that I am
not calling a double free() and that _internalObject actually does
piont to something.
The code from which the copy constructor is initiated is below...
Object * o = new Object();
if (o != NULL) {Object p = *o; //etc....}
the app only crashes when I copy the object, all other constructors
are fine. Does anyone have any ideas what may cause this?
Many thanks in advance.
Phil.
I have been writing apps in C++ for a while now but I have to admit
the below problem has stumped me - I would not consider myself an
'expert' but also I am not a novice. Any help would be appreciated.
I have a copy constructor which is defined as follows:
Object::Object(const Object& o) {
if (o != NULL) {
if (_internalObject != NULL) {
delete _internalObject;
_internalObject = NULL;
}
_message = ex.Message();
if (o.InternalObject() != NULL) {
_internalObject = new Object();
_internalObject = ex.InternalObject();
}
}
}
When I get to the line that deletes the internal object (which is a
pointer that is initialized during the constructor) I get
EXC_BAD_ACCESS. I have debugged the app and I can confirm that I am
not calling a double free() and that _internalObject actually does
piont to something.
The code from which the copy constructor is initiated is below...
Object * o = new Object();
if (o != NULL) {Object p = *o; //etc....}
the app only crashes when I copy the object, all other constructors
are fine. Does anyone have any ideas what may cause this?
Many thanks in advance.
Phil.