Pass by value or reference, to a C++ constructor that needs to store a copy?

前端 未结 8 2179
刺人心
刺人心 2020-12-11 19:50

Should a C++ (implicit or explicit) value constructor accept its parameter(s) by value or reference-to-const, when it needs to store a copy of the argument(s) in its object

8条回答
  •  感动是毒
    2020-12-11 20:34

    Hold a shared_pointer to bar in your class and pass it as such. That way you never call the copy constructor :).

提交回复
热议问题