What is the difference between a copy constructor and an
overloaded assignment operator?
Answer Posted / neelkamal yadav
A copy constructor constructs a new object by using the content of the argument object. An overloaded assignment operator assigns the contents of an existing object to another existing object of the same class.
First, the applicant must know that a copy constructor is one that has only one argument of the same type as the constructor. The compiler invokes a copy constructor wherever it needs to make a copy of the object, for example to pass an argument by value. If you do not provide a copy constructor, the compiler creates a member- by-member copy constructor for you.
You can write overloaded assignment operators that take arguments of other classes, but that behavior is usually implemented with implicit conversion constructors. If you do not provide an overloaded assignment operator for the class, the compiler creates a default member- by-member assignment operator.
This discussion is a good place to get into why classes need copy constructors and overloaded assignment operators. If the applicant discusses these with respect to data member pointers that point to dynamically allocated resources, the applicant probably has a good grasp of the problem.
Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Write about the local class and mention its use?
Describe new operator and delete operator?
Comment on local and global scope of a variable.
Which recursive sorting technique always makes recursive calls to sort subarrays that are about half size of the original array?
What is c++ map?
What is bubble sort c++?
You have two pairs: new() and delete() and another pair : alloc() and free(). Explain differences between eg. New() and malloc()
Does dev c++ support c++ 11?
In the derived class, which data member of the base class are visible?
What's the hardest coding language?
Is overriding possible in c++?
What is data types c++?
What is constructor in C++?
Why should you learn c++?
Differentiate between a copy constructor and an overloaded assignment operator.