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.
做这样的事情安全吗?我不确定执行顺序是否得到保证。
auto foo = std::make_unique<Foo>(); foo->Bar(std::move(foo));
它会正常工作。
序列:
std::move(foo)
foo->
foo
Foo::Bar(...)
可能不是最干净的代码风格。
做这样的事情安全吗?
不推荐按样式预期的那样工作,因为对象foo在被移动后仍然可用。这会产生因访问已移动对象而导致错误的风险。