Copy initialization of an object is ambiguous to direct initialization, both can be used to the same extent in order to set values equal to each other.
int a = 4;
int a = int(4);
int a(4);
all of these calls are ambiguous, they all set a equal to 4. The reason for a copy constructor in the case of an integer is convenience, imagine c++ data types without this
int a(foo(b,r)); //a little messy for a variable declaration
int a = foo(b,r) //ok, cleaner
you also might might to use an implicit and explicit copy constructor, here is an example program that uses a copy constructor explicitly to handle imaginary numbers:
#include <iostream>
using std::cout;
using std::endl;
class complexNumbers {
double real, img;
public:
complexNumbers() : real(0), img(0) { }
complexNumbers(const complexNumbers& c) { real = c.real; img = c.img; }
explicit complexNumbers( double r, double i = 0.0) { real = r; img = i; }
friend void display(complexNumbers cx);
};
void display(complexNumbers cx){
cout<<"Real Part: "<<cx.real<<" Imag Part: "<<cx.img<<endl;
}
int main() {
complexNumbers one(1);
display(one);
complexNumbers two =2;
display(200);
return 0;
}