[英]Can the 'auto' keyword be used as a storage class specifier in C++11?
可以將auto
關鍵字用作C ++ 11中的存儲類說明符嗎?
以下代碼在C ++ 11中是否合法?
int main() {
auto int x;
}
沒有代碼在C ++ 11中不正確。 C ++ 11中的auto
將用於從其初始化程序中推導出變量的類型,並且不能用作存儲類說明符。
正確使用
int main()
{
auto x = 12; // x is an int
auto y = 12.3; // y is a double
}
auto int x;
是循環的 - 你實際上將類型聲明為int
。 鑒於您擁有此信息 - 沒有理由不簡單地使用:
int x;
如果你想聲明x是范圍內另一個變量的類型,你可以使用decltype
using sometype = float;
sometype y;
decltype(y) x;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.