Follow this blog by Email

Sunday, 14 July 2013

                                      C++ Copy constructors   


Copy constructor is a special type of constructor invoked when initializing an object of a class when the object is created. During the creation, if  a implicit type conversion happens, due to arguments  passed to the object of a class during, the copy constructor needs a const reference as its argument in the constructor definition and declaration, else the compiler complains as it is a violation of standard[To paraphrase the relevant clause in C++ Standard: "An rvalue cannot bind to a non-const reference. "

The below post explains the problem in simple terms:-
http://stackoverflow.com/questions/17597870/c-array-of-objects-of-a-class-with-overloaded-constructors

No comments: