0

Possible Duplicate:
Calling assignment operator in copy constructor

I find that I am always implementing my copy-constructors as wrappers of my assignment operator, as follows:

MyClass(const MyClass& orig)
{
    *this = orig;
    //Sometimes I use the following - they are equivalent, right?
    //this->operator=(orig);
}

I am wondering if there is something wrong with this, or if there is ever a situation where the above would be wrong, or cause unwanted results.

Community
  • 1
  • 1
Baruch
  • 20,590
  • 28
  • 126
  • 201
  • If you *need* to implement a copy constructor in the first place, chances are that this just won't work. Assignment requires a fully constructed object on the left side, and if there is a need for this constructor, `*this` will likely not be a valid object. – UncleBens Jan 02 '12 at 15:26
  • @UncleBens By the time a constructor starts running, the object is fully constructed. Anything that needs to be done prior to full construction must be in the initialization list. – Baruch Jan 02 '12 at 16:15

0 Answers0