www.un.org/spanish/ecosoc 如果与参数有关的所有功能都看其价值,那么你是否总是通过经常提及该参数?
一位地雷问题同事说,它处理的是小类型的问题,但我不同意。
因此,这样做是有好处的:
void function(char const& ch){ //<- const ref
if (ch == a ){
DoSomething(ch);
}
return;
}
为此:
void function(char ch){ //<- value
if (ch == a ){
DoSomething(ch);
}
return;
}
他们的规模似乎与我相同:
#include <iostream>
#include <cstdlib>
int main(){
char ch;
char& chref = ch;
std::cout << sizeof(ch) << std::endl; //1
std::cout << sizeof(chref) << std::endl; //1
return EXIT_SUCCESS;
}
But I do not know if this is always the case.
I believe I m right, because it does not produce any additional overhead and it is self documenting.
However, I want to ask the community if my reasoning and assumptions are correct?