我想我從TC++ PL中學習到 「一個非const引用應該用左值初始化」。非const引用的初始化
而下面是我的問題
int f1(int &x)
{
return 1;
}
int f2()
{
return 1;
}
int f3(string &s)
{
return 1;
}
string f4()
{
return "1";
}
int main()
{
cout<<f1(f2())<<endl; // Error.
cout<<f3(f4())<<endl; // OK.
}
所以我上無法明白,爲什麼F3(F4())是正確的,而F4()的返回值是明顯不是一個左值。
它不應該工作。你用什麼編譯器? – ForEveR 2013-04-24 11:03:17
不適合我,因爲我期待。 – soon 2013-04-24 11:03:21
我編譯VS2010中的代碼。 – hwlts 2013-04-24 11:24:21