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

IS IT NECESSARY TO INITIALIZE VARIABLE? WHAT IF THE INSTANCE VARIABLE IS DECLARED final ? IS IT NECESSARY TO INITIALIZE THE final VARIABLE AT THE TIME OF THEIR DECLARATION?

0 Answers  


Program to check whether a word starts with a capital letter or not.

1 Answers   Infosys,


Can java compiler skips any statement during compilation time?

0 Answers  


What is the main feature of oop?

0 Answers  


What is abstract class in oops?

0 Answers  






for example A,B,C,D are class all the 4 class contain one method who() but the method who() implementaion is differnet among each class. the relation among the 4 class are A is base class and is inherited by B and C.and from this two B and C where D is inherited. the question is i want to display the output who() method in all the classes(A,B,C,D)the output of who() method is diferrent amond all the class(A,B,C,D) ------A------ virtuval who(print a) override | | who(print b) B C override who(print c) | | -------D------ override who(print d)

2 Answers  


Why is there no multiple inheritance?

0 Answers  


what is new modifier in C#

8 Answers   HCL,


What is multiple inheritance? Give Example

6 Answers   Mind Tree,


what is the use of template classes in c++

1 Answers  


Why do we use virtual functions?

4 Answers  


officer say me - i am offered to a smoking , then what can you say

0 Answers  


Categories