如何使用移动的对象? [英] How can moved objects be used?
本文介绍了如何使用移动的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
移动对象后,它必须是可破坏的:
After moving an object, it must be destructable:
T obj;
func(std::move(obj));
// don't use obj and let it be destroyed as normal
但是obj还可以做什么?您可以将另一个对象移入其中吗?
But what else can be done with obj? Could you move another object into it?
T obj;
func(std::move(obj));
obj = std::move(other);
这取决于确切的类型吗? (例如std :: vector可以提供您不能完全依赖所有T的特定保证.)是否需要或什至理智的是,所有类型除了要对移出的对象进行破坏之外,还应提供其他支持?
Does this depend on the exact type? (E.g. std::vector could make specific guarantees you can't rely on for all T.) Is it required or even sane that all types support something besides destruction on moved-from objects?
推荐答案
是的,您可以将另一个对象移入其中. std :: swap执行此操作.
Yes, you can move another object into it. std::swap does this.
这篇关于如何使用移动的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文