Copy constructors are called in some cases in C ++. One of them is when you have a function like
void f(CExample obj) {
In this case, when you make a call
CExample x; f( x );
CExample::CExample is called to build obj from x .
If you have the following signature
void f(CExample &obj) {
(note that obj now passed by reference), the copy constructor CExample::CExample does not call .
In the case when your constructor accepts an object to be copied by value (as is the case with the f function in the first example), the compiler will have to call the copy constructor first to create a copy (as with the f function, again), but .. oops, we must call the copy constructor to call the copy constructor. That sounds bad, right?
source share