There are multiple answers based on what you are doing with the string.
1) Using the string as an id (will not be modified). Passing it in by const reference is probably the best idea here: (std::string const&)
2) Modifying the string but not wanting the caller to see that change. Passing it in by value is preferable: (std::string)
3) Modifying the string but wanting the caller to see that change. Passing it in by reference is preferable: (std::string &)
4) Sending the string into the function and the caller of the function will never use the string again. Using move semantics might be an option (std::string &&)
相关文章
- C++中类成员使用前需要初始化的重要性
- 异常 try – finally 注意的地方
- 标准C++类std::string的内存共享和Copy-On-Write...
- 【C++】int、const char*、char*、char、string之间的转换
- golang 基础语法需要注意的
- java 练习题 大家帮我看看还有什么地方可以改进的 大家也可以收集 大家帮我看看我那些方面还需要改进的
- 大家看看我写的英语作文,有哪些需要改进的地方(二)
- 麻烦大家帮我看看我的简历有什么地方有毛病的需要改正(没有分了,请大家帮忙)
- 关于CI框架加入sphinx官方API接口文件的时候,需要注意的问题
- C++整形转化成string类型---路径拼接在批处理程序中的应用