I'm having some problems finding memory management errors in this code. The only one I see as a possible error is the deleting the dereferenced pointer, but I'm not even sure if thats correct. Some of the errors should include memory leaks, memory deletion when still in use, two objects pointing to the same object, and memory is allocated for new instances when it shouldnt be. Any help?!
class SomeClass{
public:
SomeClass(int size) {myMember = new OtherClass(thingSize);};
~SomeClass();
SomeClass(const SomeClass & other);
SomeClass & operator=(const SomeClass & other);
private:
OtherClass * myMember;
};
SomeClass::SomeClass(const SomeClass & other){
myMember = other.myMember;
}
SomeClass::~SomeClass(){
delete * myMember;
}
SomeClass & SomeClass::operator=(const SomeClass & other)
if(this != &other){
myMember = new OtherClass(*other.myMember);
}
return *this
}