when can we use copy constructor?

Answer Posted / amar

Copy constructors is used in following cases.
1) When object is passed by values to a fucntion
2) when function returns object by value
3) When new object is created from exixting object using
overlaoded = operator.

If user has not defined its own copy constructor, compiler
synthesised constructor would be called which will do
shallow copy. So if you have pointer in your class then only
the pointer value is copied and not the contents which
pointer points to.

Is This Answer Correct ?    12 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

If we want that any wildcard characters in the command line arguments should be appropriately expanded, are we required to make any special provision? If yes, which?

1012


What would happen on forgetting [], while deallocating an array through new?

638


What causes a runtime error c++?

589


What is the difference between the indirection operator and the address of oper-ator?

614


What are arithmetic operators?

544






what is pre-processor in C++?

599


What is an undefined reference/unresolved external symbol error and how do I fix it?

607


Explain how functions are classified in C++ ?

811


What are default parameters? How are they evaluated in c++ function?

671


What is a lambda function c++?

555


What is lambda in c++?

582


Define a nested class. Explain how it can be useful.

638


I want explanation for this assignment: how to connect mysql database using c/c++,please explain this detailly?

1587


Explain operator overloading.

606


Explain the virtual inheritance in c++.

602