mardi 1 janvier 2019

Function declaration with auto using new C++11 syntax but with auto& and without ->

consider the function definition below:

auto& Fnc1() { return someNonLocalVariable; }

Return type is not explicitly specified by -> in this case. But there is the & after auto keyword. Does this guarantee that a reference is returned instead of copy of the variable? Is this a supported language feature (returning reference)? With VS 2017, it works as I expect: Return a reference. But I could not find any online source to verify.

Aucun commentaire:

Enregistrer un commentaire