Is there a downside to declaring variables with auto in C++?

后端 未结 14 2085
-上瘾入骨i
-上瘾入骨i 2020-12-12 18:14

It seems that auto was a fairly significant feature to be added in C++11 that seems to follow a lot of the newer languages. As with a language like Python, I ha

14条回答
  •  醉酒成梦
    2020-12-12 18:50

    As I described in this answer auto can sometimes result in funky situations you didn't intend. You have to explictly say auto& to have a reference type while doing just auto can create a pointer type. This can result in confusion by omitting the specifier all together, resulting in a copy of the reference instead of an actual reference.

提交回复
热议问题