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.

>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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.