我知道之间的区别的auto,auto&,const auto和const auto&(例如在"每个"循环),但有一两件事令我惊讶的是:
std::string bla;
const std::string& cf()
{
return bla;
}
int main (int argc, char *argv[])
{
auto s1=cf();
const std::string& s2=cf();
s1+="XXX"; // not an error
s2+="YYY"; //error as expected
}
Run Code Online (Sandbox Code Playgroud)
那么有人可以告诉我何时x表达式auto x = fun();中的类型与返回值的类型不是同一类型fun()?