Why a "operator=(...)" when there is a copy ctor?
Answers were Sorted based on User's Feedback
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 |
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 |
What is the difference between a constructor and a destructor?
What is ambiguity in c++
What do you mean by abstraction?
Why can't we have instance(stack) of a class as a member of the same class like eg.Class A{A obj;} as we can have self refential pointer
What is friend function?
What is OOPS and How it is different from Procedural Programming ?
23 Answers HP, Infosys, Thyrocare,
Explain the concepts involved in Object Oriented programming.
What is the concept of object oriented program?
OOP'S advantages of inheritance include:
In the following declaration of main, "int main(int argc, char *argv[])", to what does argv[0] usually correspond? 1) The first argument passed into the program 2) The program name 3) You can't define main like that
what is difference between class template and template class?
Which method cannot be overridden?