gpt4 book ai didi

c++ - 为什么在没有 std::move 的情况下不调用 move 构造函数?

转载 作者:搜寻专家 更新时间:2023-10-31 01:02:57 25 4
gpt4 key购买 nike

我有这个代码:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com