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

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

1786


What is a stl vector?

628


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

1649


Do you like to Submit Questions in Bulk under Same Category?? Then use our Bulk ListerDo you like to Submit Questions in Bulk under Same Category?? Then use our Bulk Lister

1667


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

1898






how to use C++?

2069


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

2329


Is string part of stl?

681


Can we use stl in coding interviews?

1287


Who wrote stl?

683


What is stl stack?

665


Why should a c++ programmer be interested in stl?

647


what is template and type convertion

2000


What is meant by stl in c++?

657


Write a C/C++ program to add a user to MySQL. The user should be permitted to only "INSERT" into the given database.

2098