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 a standard template library (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  


method overloading means what?

2 Answers   CTS,


What is the stl, standard template library?

0 Answers  


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

0 Answers  






What is Constructor

14 Answers   Angel Broking,


5. Write c++ function that would intake a string and return the number of occurrences of a given character in that sring Ex:- if the word is “Colombo” and count the occurrences of the letter “o” the function would return 3

1 Answers  


Write a program in C++ to concatenate two strings into third string using pointers

5 Answers  


How can you create a bulleted list, numbered list and an outline by using bullets and numbering command. Explain with the help of example.

0 Answers  


i want a road rash 3d game code if some one know please help me

1 Answers  


What is the disadvantage of templates ?

2 Answers   NSN, Symphony,


I am doing my BS.c MATHS CAN I ABLE TO JOIN IN NIIT?

2 Answers  


Categories