What is the difference between overloading the operator = in a class and the copy constructor?
In which context is each one called?
I mean, if I have the following:
Person *p1 = new Person("Oscar", "Mederos");
Person *p2 = p1;
Which one is used? And then when the other one is used?
Edit:
Just to clarify a little bit:
I already know that if we explicitly call the copy constructor Person p1(p2), the copy constructor will be used. What I wanted to know is when each one is used, but using the = operator instead, as @Martin pointed.
In your case neither is used as you are copying a pointer.
The copy constructor
An assignment:
It is worth mentioning that that the assignment operator can be written in terms of the copy constructor using the
Copy and Swapidium: