why & sign is used in copy constructor

Answer Posted / sandip

To avoid local copy of object reference (&) is used in copy
constructor.
Moreover if the & is ommited then copy constructor goes in
infinite loop.
eg. if class name is Sample.

Copy constructor without &
Sample :: Sample (Sample s)
{
//Code goes here
}

and we create object as follows. ;
Sample s;
Sample s1(s);

In this scenario program will go in infinite loop.

Is This Answer Correct ?    9 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is stl stand for?

815


i wanted to know about questions about c,c++ , which is required for placements.... im a fresher

1796


how to making game in c++ ?

2290


write a program to convert a decimal number in to its equivalent binary number?

2165


What is a standard template library (stl)? What are the various types of stl containers?

776






how can u do connectivity in c++ language? plz send me connectivity code in c++ ?

1997


Name the different types of stl containers.

791


totoo po ba ang manga aliens!

2423


Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.

2069


What is meant by stl in c++?

779


To modify an, existing worksheet. What steps are involved for: 1. Inserting and deleting rows and columns. 2. Printing cell formulas 3Jld displayed values 3. Using the page setup command

1867


What do stl stand for?

751


In what scenario does the Logical file and Physical file being used?

2428


What are the different types of stl containers?

746


Describe how to safeguard a system through acquisition of an antivirus Program and systematic backup.

1737