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

前端 未结 7 717
谎友^
谎友^ 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:48

    syntax has to be unambiguous and also backward compatible.

    If auto is dropped there will be no way to distinguish between statements and definitions.

    auto n = 0; // fine
    n=0; // statememt, n is undefined.
    

提交回复
热议问题