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

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

    Look this question.

    Use const T & arg if sizeof(T)>sizeof(void*) and use T arg if sizeof(T) <= sizeof(void*). All fundamental types should be the exception to this rule

提交回复
热议问题