auto keyword behavior with references

ⅰ亾dé卋堺 提交于 2019-12-01 17:04:38

When auto is deduced, it is not deduced to the reference. It always deduces to the value. If you want to have a reference to returned value, you can have auto&, const auto& or auto&&.

And yes, it is by design. Any other behavior would actually be quite surprising. What is even worse, it is easy to use a reference when you want. However, imagine that auto would be actually deduced to the reference. How would you (syntactically) make it a value?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!