Answers

Question and Answer:

  Home  Standard Template Library (STL)

⟩ Why & sign is used in copy constructor?

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.

 192 views

More Questions for you: