in C Plus Plus by
Q:

What is the difference between a Copy Constructor and an Overloaded Assignment Operator?

1 Answer

0 votes
by

A copy constructor and an overloaded assignment operator basically serve the same purpose i.e. assigning the content of one object to another. But still, there is a difference between the two.

Example:

complex c1,c2;

c1=c2; //this is assignment

complex c3=c2; //copy constructor

In the above example, the second statement c1 = c2 is an overloaded assignment statement.

Here, both c1 and c2 are already existing objects and the contents of c2 are assigned to the object c1. Hence, for overloaded assignment statement both the objects need to be created already.

Next statement, complex c3 = c2 is an example of the copy constructor. Here, the contents of c2 are assigned to a new object c3, which means the copy constructor creates a new object every time when it executes.

Click here to read more about Loan/Mortgage
Click here to read more about Insurance

Related questions

+1 vote
+1 vote
asked Jul 16, 2019 in C Plus Plus by Indian
0 votes
asked Jun 15, 2020 in C Plus Plus by Robindeniel
0 votes
asked Jun 23, 2019 in PHP by SakshiSharma
0 votes
asked Mar 17, 2020 in C Plus Plus by SakshiSharma
0 votes
asked Jan 6 in C Plus Plus by GeorgeBell
...