C++ 左值、右值、将亡值
考虑以下代码: class DiskFile { public: DiskFile(const std::string file_path_) :file_path(file_path_) {} protected: std::string file_path; }; 我们可以这样实例化: DiskFile df_1("./test.df"); DiskFile df_2(std::string("./test.df")); 这其中的问题是,file_path被复制了一次,file_path_被复制一次,有性能损失。我们可以通过std::move进行优化: class DiskFile { public: DiskFile(const