【发布时间】:2014-01-23 10:14:41
【问题描述】:
这是cppcheck show warning "[event.cpp:20]: (performance) Function parameter 'path' should be pass by reference."的代码
void
event::set_path(const std::string path)
{
this->_path = path;
}
但包括字符串参数在内的其他代码不显示此警告,例如:
int
watcher::init_watch(const struct stat *sb, std::string path, bool linked)
{
int wd;
....
}
为什么?
【问题讨论】:
-
通过
constvalues 传递参数和返回值被破坏,因为它禁止所有形式的移动语义。