【发布时间】:2020-09-11 10:52:14
【问题描述】:
我刚刚创建了一个将右值引用作为参数的函数,但是如果我传递 '67',它可以工作,但是假设“int&& ref = 67”,如果我将 ref 作为参数传递它会引发错误。
#include <iostream>
using namespace std;
void func(int&& a){
std::cout << a << " from rvalue" << std::endl;
}
int main(){
int&& ref = 6;
//func(ref); // error
func(6); // holds good
return 0;
}
// error -> cannot bind rvalue reference of type 'int&&' to lvalue of type 'int'
我不知道为什么它说左值是'int'类型,甚至参数是'int&&'类型(右值不是左值) 帮我看看有什么问题。 提前致谢......
【问题讨论】:
标签: c++ rvalue-reference