What is the difference between a copy constructor and an
overloaded assignment operator?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
What is pointer to member?
Design a program to input a date from user in the form day/month/year (e.g. 2/6/2000) and report whether it’s a valid date or not. The program should take account of leap years. You will need to know that a leap year is a year that is exactly divisible by 4, except that century years are only leap years if they are divisible by 400.
Problem 5: Hero's Formula is A method for calculating the area of a triangle when you know the lengths of all three sides. Let a, b, c be the lengths of the sides of a triangle. The area is given by:A= pp-ap-b(p-c) | wherep= a+b+c2 | | Write a C-language code to calculate area of triangle using above method. Take the three lengths of the triangle from the user and display the area that your program calculates.
What is an arraylist c++?
write the programme that convert a interger to biniry number
check whether a no is prime or not.
What is this pointer in c++?
What are the advantages of inheritance in c++?
How do you declare A pointer to function which receives an int pointer and returns a float pointer
What is a stack c++?
what are function pointers?
How can you quickly find the number of elements stored in a a) static array b) dynamic array ? Why is it difficult to store linked list in an array?how can you find the nodes with repetetive data in a linked list?