What are the benefits to passing integral types by const ref

前端 未结 12 2059
情话喂你
情话喂你 2021-02-05 22:18

The question: Is there benefit to passing an integral type by const reference as opposed to simply by value.

ie.

void foo(const int& n); // case #1
<         


        
12条回答
  •  我寻月下人不归
    2021-02-05 22:54

    I can't think of any benefit. I've even seen recommendation that when writing templates, you use meta-programming to pass integral types by value and only use const reference for non-integral types.

提交回复
热议问题