我有这个代码:
SomeType::SomeType(std::vector<Item>&& container, const float someOtherPArameter)
: internal_container(std::move(container))
{
// some code here
}
有人可以向我解释为什么 move 构造函数不会在没有“std::move”的情况下调用“internal_container”吗?
最佳答案
每当从相同类型的 xvalue 初始化对象时,都会调用 move 构造函数。您可以通过调用 std::move(x)
创建该 xvalue
。将参数声明为右值引用不会自动使其成为xvalue
。
关于c++ - 为什么没有 std::move 就不会调用 move 构造函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26269345/