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
How static variables and local variablesare similar and dissimilar?
What is stack unwinding?
Write a program for Divide a number with 2 and Print the output ( NOTE: Check for divide by zero error).
Define basic type of variable used for a different condition in C++?
Describe new operator and delete operator?
Explain the virtual inheritance in c++.
What is a memory leak c++?
What is cout flush?
Define pure virtual function?
Please explain the reference variable in c++?
There are 100 students in a class. The management keep information in two tables. Those two tables are given like Roll no Name Age 001 ABC 15 002 XYZ 14 and Roll No Subject Marks 001 Math 75 001 Physics 55 002 Math 68 001 Hindi 69 They want the information like this Roll No Name Hindi Physics Math Total 001 ABC 69 55 75 199 002 XYZ 68 74 84 226 And Roll No Suject Highest 001 Math 98 007 Physics 84 021 Hindi 74 All 275 All information is kept in structure in main memory. You have to find last two tables.
What does flush do?
Explain the different access specifiers for the class member in c++.
How one would use switch in a program?
Distinguish between a # include and #define.