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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…