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 |
Why should a c++ programmer be interested in stl?
what is the acronym of the term 'C.O.M.P.U.T.E.R' ?
17 Answers Config Systems, Google, Wipro,
how can u do connectivity in c++ language? plz send me connectivity code in c++ ?
What is meant by stl in c++?
What is a list in c++ stl?
What is the underlying datastructure of map?
Write a program in C/C++ to implement reader- writer problem
differentiate between private, public and protected data members of the class using example.
write a c++ to define a class box with length,breadth and height as data member and input value(),printvalue() and volume() as member functions.
How to write a function that goes through an array of characters and eliminates any elements that are not letters (Legal letters can be either in an uppercase or a lowercase format.) The function removeNonLetters should return the new effective size of the array as the result.
Diffrernce Between Overloading and Overriding?
write a program to convert a decimal number in to its equivalent binary number?