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

后端 未结 2 1203
小鲜肉
小鲜肉 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:32

    auto int x;
    

    is circular - you are literally declaring the type as an int. given that you had this information - there is no reason to not simply use:

    int x;
    

    if you wanted to declare x the type of another variable in scope you can use decltype

    using sometype = float;
    sometype y;
    decltype(y) x;
    

提交回复
热议问题