0

Hi,
Can someone expain why ompiler provide default Copy Constructor for every class. As i know there is only one reason that if Compiler does not provide the copy constructor, f we pass the object by value or we create a new object from existing object or we return object as value then our programme struck in infinite loop.Is there any other reason for compiler to provide default copy constructor.


Secondly i need to know the difference between copy constrcutor and assignment operator.

Thanks in Advance.

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by Narue
0

>Can someone expain why ompiler provide default Copy Constructor for every class.
It's largely for convenience. If your members have the right copying semantics, you don't have to write out an explicit copy constructor and worry about making a mistake. You can also rely on any optimizations by the compiler with the default member functions.

>then our programme struck in infinite loop.
No, I'd wager that the rules would lean more toward if there's not a copy constructor, your program would fail to compile in those cases.

>Secondly i need to know the difference between copy constrcutor and assignment operator.
That's easy. A copy constructor creates a new object using the contents of an existing object and the assignment operator copies the contents of an existing object into another existing object. The difference is whether a new object is created or not.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.