Copying a C++ class with a member variable of reference type

后端 未结 7 2388
清酒与你
清酒与你 2020-12-30 06:06

I\'ve a class which stores a reference to its parent, the reference is passed in the constructor. If I try to copy an instance I get an error \"error C2582: \'operator =\' f

7条回答
  •  长发绾君心
    2020-12-30 06:41

    You need to implement a copy constructor and initialize the reference in that copy constructor, to point to the same reference as the original object.

提交回复
热议问题