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

design a c++ class for the chess board,provide a c++ class definition for such class(only class definition is required)

6143


What is abstract class in oop?

526


What is polymorphism what is it for and how is it used?

572


What is byval and byref? What are differences between them?

1687


What are objects in oop?

604






Are polymorphisms mutations?

693


What is this pointer in oop?

551


What is the real time example of inheritance?

635


What are oops methods?

563


What is encapsulation in oops?

534


What is class and object in oops?

607


What does and I oop mean?

610


What is a class and object?

594


Give an example where we have to specifically use C programming language and C++ programming language cannot be used?

1145


What is the difference between static polymorphism and dynamic polymorphism?

579