If i remove '&' symbol from copy constructor what will happen(in c++)?
Two things, and they are both pretty bad.
First, if you don't put the & symbol, then your function isn't a true copy constructor. You can still use it to make copies, but the compiler won't know about it. Recall that when you pass an object into a function by value, its copy constructor is called "behind the scenes" to make a copy of the object which is then used by the function. If you don't implement the correct copy constructor, then the internal copy won't be correct and you can easily mess up pointers inside the object.
Second, remember that you're already making a copy every time you pass an object by value (without the & sign). If you make a "copy" constructor without the &, you're effectively making a copy of the object, then copying the copy into a third object, and throwing away the first copy. That's very wasteful. If you're working with large objects this way, then your program will be very slow and will consume loads of memory.
If i remove '&' symbol from copy constructor what will happen(in c++)?c++ string
I don't know what you mean clearly, but the main purpose of copy constructor is to create a duplication of the object, so the input parameter can be passed into in many ways, and, you must guarantee that the real data of input object is not changed through duplicating operation.
Have funs
More Related Questions and Answers ...
The information post by website user , we not guarantee correctness.
Dental Treatment Skin Whitening Skin Problems Skin Rashes Shoes
