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

前端 未结 8 2178
刺人心
刺人心 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:30

    Stylistically, I'd say that passing by reference is the better way.

    If the performance really matters, then don't guess. Measure it.

提交回复
热议问题