I am having trouble understanding 2 things.
1. the difference between a copy constructor and an operator=
What the actual use of the copy constructor is. I think I get the
2. do we actually call the operator= or is it called whenever it is
The copy constructor, like all constructors, is only called once in an object's lifetime. Even when you do something like this,
type a = b; // looks like assignment, but isn't
It's the same as
type a(b); // it's actually a copy constructor call
However, if you want to change the state of an object to another object AFTER it has been created, that is when you use the operator =.
All calls to the = operator are explicit, but not everything that looks like it's using the = operator actually does.
type a(2); // type(int) constructor
type c(a); // type(const type&) [copy constructor]
type b; // type() [default constructor]
b = a; // operator = (type, type)
the copy constructor is also called when an object is passed-by-value to a function and when a function returns an object