auto
、auto&
、const auto
およびconst auto&
(たとえば「for each」ループ内)の違いは知っていますが、1 つ驚いたことは次のとおりです。
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
}
x
では、式auto x = fun();
の の型が の戻り値の型と同じ型にならない場合を誰か教えてもらえfun()
ますか?