這是cppcheck show waring的代碼[[event.cpp:20] :(性能)函數參數'path'應該通過引用傳遞。「爲什麼cppcheck說「函數參數應該通過引用傳遞」?
void
event::set_path(const std::string path)
{
this->_path = path;
}
但其他代碼,包括串paramer不顯示此警告,如:
int
watcher::init_watch(const struct stat *sb, std::string path, bool linked)
{
int wd;
....
}
爲什麼呢?
傳遞參數並通過'const' * values *返回值被破壞,因爲它禁止所有形式的移動語義。 – Griwes