Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
给定这个构造函数:
MyClass::MyClass(SomeOtherClass other) : myOther(other) { }
我应该std::move在初始化列表中手动调用,还是编译器足够聪明以自动执行它?
std::move
你必须打电话给它。编译器无法知道您以后是否仍想“使用”该对象(无论如何这将是一个非常混乱的语言规则)。所以说: myOther(std::move(other))。
: myOther(std::move(other))