Why & sign is used in copy constructor?
Submitted by: AdministratorTo 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.
Submitted by: Administrator
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.
Submitted by: Administrator
Read Online STL Job Interview Questions And Answers
Top STL Questions
☺ | Write a program in C/C++ to implement reader- writer problem? |
☺ | Write a program in C++ returning starting locations of a substring using pointers? |
☺ | Why & sign is used in copy constructor? |
☺ | 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? |
☺ | WHAT IS THE DIFFERENCE BETWEEN C++ AND VC++? |
Top Coding/Programming Categories
☺ | Python Interview Questions. |
☺ | OOP Interview Questions. |
☺ | Software engineering Interview Questions. |
☺ | PHP Interview Questions. |
☺ | VBA (Visual Basic for Applications) Interview Questions. |