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

Answers were Sorted based on User's Feedback



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

Answer / 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

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

Answer / arun

Copy Constructor means creation of new object and after that
copy properties of some exiting object to newly created object.

Overloading assignment operator is that copy properties of
some exiting object to another exiting object of same type.

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More OOPS Interview Questions

Finding of the 4 larger (bigger) numbers from the list like{1245,4587,2145,1163,29987,65783.....}

1 Answers   Wipro,


Why we use classes in oop?

0 Answers  


What are the 5 oop principles?

0 Answers  


What do you mean by variable?

0 Answers  


What is abstract class in oop?

0 Answers  


Why is static class not inherited?

0 Answers  


What are the advantanges of modularity

2 Answers  


Please tell me the oops concept with detailed answer

9 Answers   EEE,


i ahve v low % in 12th n BSC which is aroun 50 coz science was imposed on me......nw m doin MCA n my aggregate in above 74%,what shud i say if asked about low previous percentage??????

4 Answers  


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

0 Answers   CAT,


what is virtual function?

3 Answers  


what is ns string? what is ns array?

1 Answers  


Categories