Saturday 23 June 2012

What is the difference between a copy constructor and an overloaded assignment operator?

class C
{
public:
C();
C(const C& c);
C& operator=(const C& c)
};

C c1; // default c-tor
C c2 = c1; // copy c-tor
C c3(c2); // copy c-tor
C c4; // default c-tor
c4 = c3; // assignment operator

A copy constructor constructs a new object by using the content of the argument object. An overloaded assignment operator assigns the contents of an existing object to another existing object of the same class.

No comments:

Post a Comment