在Google c ++代码样式中,他们表示在某些情况下使用const T*
优于const T&
作为输入参数。
我不明白第二个。你能给我一些例子吗?谢谢。
答案 0 :(得分:1)
在某些情况下,使用const T *优于const T&作为输入参数
2。该函数保存指向输入的指针或引用。我不明白第二个。你能给我一些例子吗
示例:
int* ptr;
void foo(int& ref)
{
ptr = &ref; // function saves a pointer or reference to the input
// therefore using ref input is not preferable
// according to the guideline
}