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 a standard template library (stl)?
Write a program in C++ to concatenate two strings into third string using pointers
Waht is inheritance
Give the output of the following program main() {int ret; ret=fork();ret=fork();ret=fork();ret=fork(); if(!ret) printf("sun"); else printf("solaris");
why & sign is used in copy constructor
What is stl stand for?
what is an algorithm in terms of STL?
write a program that input four digit number and find how many 7 that number contains
what is strcture i++ i ++i answer to this i=5 what is the out put
What does stl mean in slang?
Assume I have a linked list contains all of the alphabets from "A" to "Z?" I want to find the letter "Q" in the list, how does you perform the search to find the "Q?"
Find the error in the following program struct point {struct point *next; int data; } x; main() {int...data; } x; main() {int i; for(x=p;x!=0;) x=x->next,x++; freelist(x); } freelist(x) {free(x); return }