What is the difference between a copy constructor and an
overloaded assignment operator?

Answers were Sorted based on User's Feedback



What is the difference between a copy constructor and an overloaded assignment operator?..

Answer / guest

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.

Is This Answer Correct ?    44 Yes 12 No

What is the difference between a copy constructor and an overloaded assignment operator?..

Answer / siddharth wighe

Second main difference:
A copy constructor has no return type, whereas an
overloaded assignment operator has one.

Third difference (trivial):
Name of the copy constructor is the same as that of the
class in which it is defined

----------------------
http://swighe.nipl.net

Is This Answer Correct ?    32 Yes 7 No

What is the difference between a copy constructor and an overloaded assignment operator?..

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

What is the difference between a copy constructor and an overloaded assignment operator?..

Answer / vsinghal

In case of copy constructor when the object goes out of
scope its destructor will be called while in case of
assignment operator no destructor will be called.

Is This Answer Correct ?    12 Yes 14 No

Post New Answer

More C++ General Interview Questions

Does c++ have finally?

0 Answers  


What is copy constructor? Can we make copy constructor private in c++?

0 Answers  


When is the last time you coded in C/C++? What is the most lines of original C/C++ code you have personally written in one project? How confident are you in your ability to write C or C++ without a reference?

1 Answers   Microsoft,


Can notepad ++ run c++?

0 Answers  


what do you mean by memory management operators

4 Answers   HCL,






What are the techniques you use for debugging?

1 Answers   Adtran,


i want to know how to copy arrary without using any method or function. I have tried the below using System; class e4 { static void Main(string[] args) { int a,b; int[ ] m= new int[5]; int[ ] n= new int[5]; for(a=0;a<=4;a++) { Console.WriteLine("enter any value"); m[a]=Convert.ToInt32(Console.ReadLine()); m[a]=n[a]; } for(b=0;b<=4;b++) { Console.WriteLine(n[b]); } } } but it will give wrong result can anyone solve this problem

1 Answers   Reliance,


What is the role of static keyword for a class member variable?

0 Answers  


Declare a class vehicle and make it an abstract data type.

0 Answers  


Is oops and c++ same?

0 Answers  


Differentiate between a template class and class template in c++?

0 Answers  


Why is c++ still used?

0 Answers  


Categories