why & sign is used in copy constructor

Answers were Sorted based on User's Feedback



why & sign is used in copy constructor..

Answer / 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

why & sign is used in copy constructor..

Answer / neha

Here as address of the object is taken into consideration
thats why here & sign is used

Is This Answer Correct ?    7 Yes 3 No

why & sign is used in copy constructor..

Answer / krishnarao panchadi

Sandip, Good answer. It goes into Infinete loop because, as
the a local copy of the object is created, it will call the
constuctor one more time and another copy will be created
there and so on...

Is This Answer Correct ?    2 Yes 0 No

why & sign is used in copy constructor..

Answer / diraj kumar

it copy con command c baset of lan leval

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More STL Interview Questions

What is the stl, standard template library?

0 Answers  


What is a list in c++ stl?

0 Answers  


Who created stl?

0 Answers  


Distinguish between: a) Normal layout & Print Layout views b) Windows Clipboard & office Clipboard c) Save & Save As Commands d) Program File & Data File e) Pie Charts & Barr Charts

0 Answers  


Explain how to insert a hyperlink in to an Excel worksheet and save a Word document as a Web page.

1 Answers  






why we are using the fork command?.. how it works?

1 Answers  


What is meant by stl in c++?

0 Answers  


Describe the My Computer and My Documents folders; identify the elements that are present in every Window.

0 Answers  


WHAT IS FIBONACCI SERIES?

4 Answers   Stewart,


How stl is different from the c++ standard library?

0 Answers  


Define stl.

0 Answers  


why & sign is used in copy constructor

4 Answers  


Categories