Can the 'auto' keyword be used as a storage class specifier in C++11?

后端 未结 2 1187
小鲜肉
小鲜肉 2021-01-17 16:34

Can the auto keyword be used as a storage class specifier in C++11?

Is the following code legal in C++11?

int main() {
   auto int x;
}
         


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-17 17:24

    No the code is ill-formed in C++11. auto in C++11 would be used to deduce the type of a variable from its initializer and it can't be used as a storage class specifier.

    Correct Usage

    int main()
    {
       auto x = 12; // x is an int
       auto y = 12.3; // y is a double
    }
    

提交回复
热议问题