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

write a function signature with various number of parameters.

538


What will happen if a pointer is deleted twice?

703


Explain how we implement exception handling in c++?

557


How would you use the functions memcpy(), memset(), memmove()?

599


What is virtual table?

586






What is the latest c++ version?

590


Explain virtual destructor?

642


Why is c++ still used?

576


What are arithmetic operators?

508


Define friend function.

544


What is abstract keyword in c++?

572


Would you rather wait for quicksort, linear search, or bubble sort on a 200000 element array? (Or go to lunch...) a) Quicksort b) Linear Search c) Bubble Sort

611


What is an undefined behavior and sequence points

544


If dog is a friend of boy, is boy a friend of dog?

546


What are static and dynamic type checking?

587