why & sign is used in copy constructor
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
What is the stl, standard template library?
What is a list in c++ stl?
Who created stl?
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
Explain how to insert a hyperlink in to an Excel worksheet and save a Word document as a Web page.
why we are using the fork command?.. how it works?
What is meant by stl in c++?
Describe the My Computer and My Documents folders; identify the elements that are present in every Window.
WHAT IS FIBONACCI SERIES?
How stl is different from the c++ standard library?
Define stl.
why & sign is used in copy constructor