If i remove '&' symbol from copy constructor what will happen(in c++)?

 Dont Buy Textbooks. Rent 'EM Save 60-80%



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 ...
  • What is the difference between copy construct..
  • What will happen if we declare a Constructor ..
  • In C++ how do you write a constructor functio..
  • In C++ when should you define a copy construc..
  • Program in c++ to add two valid date using co..
  • Why doesnt constructor doesnt have ne return ..
  • In C++ what is the purpose of a copy construc..
  • Can someone explain to me what is copy constr..
  • C++ constructors?
  • In c++, is it possible for a derived class to..
  • Create a class, in C++, of name matrix. Add t..
  • C++: What's the diference between ov..
  • Constructors and C array question in C++?
  • Defualt constructors, copy constructors, and ..
  • Does the destructor in C++ have a definition ..
  • Help in C++ regarding constructors.(basic que..
  • C++ classes & constructors?
  • C++ Program Help! (Using classes)?
  • I have this program in c# for constructors.it..

  • The information post by website user , we not guarantee correctness.

    

    Dental Treatment Skin Whitening Skin Problems Skin Rashes Shoes