Sha*_* Li 5 c++ move rvalue-reference c++11 forwarding-reference
根据cppreference.com,move有签名
template< class T >
typename std::remove_reference<T>::type&& move( T&& t ) noexcept;
Run Code Online (Sandbox Code Playgroud)
为什么它需要一个右值参考T&& t作为它的arugment?
当我尝试以下代码时
void foo(int&& bar) {
cout << "baz" << endl;
}
int main(){
int a;
foo(a);
}
Run Code Online (Sandbox Code Playgroud)
我从编译器得到一个错误"rvalue引用不能绑定到左值"
到底是怎么回事?我很困惑.
| 归档时间: |
|
| 查看次数: |
752 次 |
| 最近记录: |