1.引用不能绑定到非左值。
#include <iostream>
using namespace std;
int a;
int main()
{
int &b=3;//错误
cout<<a<<endl;
cout<<b<<endl; return 0;
}//以上代码会报错: error C2440: 'initializing' : cannot convert from 'const int' to 'int &'
// A reference that is not to 'const' cannot be bound to a non-lvalue
2.引用必须初始化
#include <iostream>
using namespace std;int a;
int main(){
int &b;//错误
cout<<a<<endl;
cout<<b<<endl;
return 0;
}// error C2530: 'b' : references must be initialized
3.引用不能被赋值但可以通过引用来改变被引用的对象的值。
#include <iostream>
using namespace std;
int a;
#define NULL 0
int main()
{
int &b=a;
b=3;//正确
int c;
&b=c;//error C2440: '=' :cannot convert from 'int' to 'int *' //Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
&b=&c;//error C2106: '=' : left operand must be l-value
return 0;
}