char &get_val(string &str. string::size_type ix)
{
return str[ix];
}
int main()
{
string s("what the hell");
cout << s << endl;
get_val(s, 0) = 'a';
cout << s << endl;
}
调用一个返回引用的函数得到左值,其他返回类型得到右值,可以像使用其他左值那样来使用返回引用的函数的调用, 特别是,我们能为返回类型是非常量引用的函数的结果赋值。