- [pass by left-value refernece]
- [pass by right-value refernece]
点击查看代码
#include<iostream>
#include<vector>
using namespace std;
void print(int &¶m) {
cout << "param is a rignt-value reference:"
<< "param = " << param<< endl;
}
/*
// error
void print(int param) {
cout << "param is a left-value:"
<< "param = " << param<< endl;
}
*/
void print(int ¶m) {
int& p = param;
p = 100;
cout << "param is a left-value reference:"
<< "param = " << param<< endl;
}
int main() {
int a = 3;
cout << "a = " << a << endl;
print(a);// call "print(int &)"
cout << "a = " << a << endl;
cout << "" << endl;
print(std::move(a));// call "print(int &&)"
cout << "" << endl;
print(1000);// call "print(int &&)"
cout << "" << endl;
return 0;
}