Sunday, September 14, 2014

C++ Copy Constructor, Assignment Operator

Copy Constructor

Song(Song const&);
It is needed if you want to initialize an object to take the value of another one:
Song a;
Song b = a;    // Calls copy constructor
Assignment Operator
void operator=(const Song&);
It is needed for assigning a value to an already existing instance:
Song a;
Song b;
b = a;        // Calls assignment operator
Note that the standard return value for an assignment operator is a reference:
Song& operator=(const Song&);

No comments:

Post a Comment