1.引用必须在声明时将其初始化,不能先声明后赋值。
#include<iostream>
usingnamespace std;
int main()
{
int rats =10;
//声明引用,旦未初始化
int&rodents;
rodents = rats;
return0;
}
上述代码编译时会报以下错误:
error:‘rodents’ declared as reference but not initialized
错误:'rodents' 声明为引用但未初始化。