gpt4 book ai didi

C++ std move 文件错误?

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

这是 document我指的是。两种形式都将右值引用作为输入 (T&& t)。

但是我们可以将左值作为move的参数,在我下面的例子中,a是一个左值,它是可识别的和内存可寻址的。

有没有想过文档是错误的?

#include <iostream>

int main() {
string a = "hello";
string b(std::move(a));
std::cout << "a is: " << a << endl;
std::cout << "b is: " << b << endl;
}

输出,

a is: 
b is: hello

最佳答案

T&& t 不是右值引用。它是前向引用,以前称为通用引用,是与模板或自动参数一起使用时的特殊情况。在这里阅读这个很好的解释 https://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers

关于C++ std move 文件错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49332657/

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