C++ auto vs auto&

后端 未结 2 1472
不知归路
不知归路 2020-12-03 05:41

if I have a function:

Foo& Bar()
{
   return /// do something to create a non-temp Foo here and return a reference to it
}

why is this:

2条回答
  •  无人及你
    2020-12-03 06:36

    Taken directly from Herb Sutter's blog post:

    auto means “take exactly the type on the right-hand side, but strip off top-level const/volatile and &/&&.”

提交回复
热议问题