Why a "operator=(...)" when there is a copy ctor?

Answer Posted / guest

You use the assignment operator (operator = ()) whenever an
existing object is to be replaced with a different object.
The copy constructor X(const X&) is used to create a new
instance of an X-object exactly like another.

Notice the subtle difference. Assignment changes an existing
object while construction creates a new object. You can view
assignment as the application of a destructor, to flush away
the existing object, followed by a copy construction, to
make an exact copy of the assigned object.

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is an advantage of polymorphism?

815


Is html an oop?

767


any one please tell me the purpose of operator overloading

2155


write a program to enter a string like"sunil is a good boy and seeking for a job" not more than 10 characters including space in one line,rest characters should b in other line.if the next line starts from in between the previous word,then print whole word to next line.

1975


Is abstract thinking intelligence?

777


What are classes oop?

785


What is encapsulation in ict?

801


How oops is better than procedural?

811


What is the highest level of cohesion?

762


What is class and object in oops?

818


What is overriding in oop?

775


What is abstraction with example?

818


can we make game by using c

3708


What are the components of marker interface?

794


What is destructor in oop?

788