I'm having a class Place with such methods :
class Place{
protected:
Keypoint* _kp;
Place() {
Keypoint* kp = new Keypoint();
_kp = kp;
};
Place(const Place& cSource){
delete _kp;
_kp = cSource.makePointer();
}
virtual ~Place(){
delete _kp;
}
virtual Keypoint* makePointer() const {
return _kp->makePointer();
}
};
Thus a constructor, a destructor and a copy method.
In my main I do something as simple as AASS::graphmatch::Place ppp; AASS::graphmatch::Place p2(ppp); to try the copy constructor and I have a huge segfault with valgrind telling me that I use Conditional jump or move depends on uninitialised value(s) after the delete in the copy. The method makePointer in Keypoint does a new and return a pointer Keypoint*.
virtual Keypoint* makePointer() const {
Keypoint* d = new Keypoint();
return d;
}
It is my understanding that every new should be freed using delete so that's why I use delete before calling makePointer. So that's why I start by deleting _kp to release the old memory and then I assign it the newly created pointer.
I can't get my head around why I have uninitialized value ?
delete _kp;in your copy constructor, the_kphas not been initialised for the new object yet, so you're trying todelete <garbage-ptr>- BeyelerStudiosx == yprinciple... - patrikx==yprinciple is in this case :S, but what I do is that I have some class that inherit from Keypoint and instantiate pointer to their own class using makePointer(). So depending on cSource type I obtain a pointer of cSource class which is also a Keypoint. - MalcolmPlace p {}; Place p2{p}; bool eq = p==p2;, then eq should be true. You can of course define the equality operator as you want but in this case every "copy" you get would look the same as an default constructed object, which I in my view is not much of a copy. In Particular you wantf(p)andf(p2)to give the same answer and that would be hard if you have done changes topbefore copy construction. - patrik