I'm writing the class::operator=
for my c++ code, and am trying to clone the class parameter right
, in this code snippet.
myClass & myClass::operator =(const myClass &right){
myClass *abcde = new myClass(right);
myClass coolvar(right); //this and the previous line work, but don't update the class
*this = *abcde; //uses = operator, so infinitely loops
myClass *this = new myClass(right); // doesn't work [expected unqualified-id]
myClass this(right); // doesn't work [expected unqualified-id]
}
However, I can't find a way to correctly rewrite the pointers, like using *this = *abcde
, or to call the constructors on the class itself like in the bottom two lines. How would I go about this?