What is the difference between overloading operator= and overloading the copy constructor?

Viewed 4372

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.

3 Answers
Related