直接看示例代码:
int main(){
int &s1 = f.f1();
cout << s1 <<endl; //输出5
s1 = 20; //通过引用,改变了mszT
f.print(); //输出20
//int s1 = f.f1(); //语句成立,但无法通过s1改变mszT了
int &s3 = f.f3(); //语句报错,f3返回类型是const,所以接收的变量必须为const。
int const &s3 = f.f3(); // 正确
cout << s3 << endl; //输出 5
s3 = 20