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

后端 未结 14 2081
-上瘾入骨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:38

    One of the drawbacks is that sometimes you can't declare const_iterator with auto. You will get ordinary (non const) iterator in this example of code taken from this question:

    map usa;
    //...init usa
    auto city_it = usa.find("New York");
    

提交回复
热议问题