# C++ Notes: Why use const std::string& name instead of std::string name?
在一个function里,why f(const std::string& name) is better than f(std::string name)?
- const std::string& name: pass in by reference
const 代表只读,引用的好处是更节省内存,引用只占4字节。同时用reference节省时间的开销。
- std::string name: pass in by value
调用时,实际调用函数时,先有一个copy的过程,然后传参。