Why do I need to explicitly write the 'auto' keyword?

前端 未结 7 710
谎友^
谎友^ 2020-12-14 05:34

I am moving towards C++11 from C++98 and have become familiar with the auto keyword. I was wondering why we need to explicitly declare auto if the

7条回答
  •  再見小時候
    2020-12-14 05:59

    Dropping the explicit auto would break the language:

    e.g.

    int main()
    {
        int n;
        {
            auto n = 0; // this shadows the outer n.
        }
    }
    

    where you can see that dropping the auto would not shadow the outer n.

提交回复
热议问题