編譯器錯誤 C2513

'type' : '=' 之前未宣告任何變數

類型規範會出現在宣告中,沒有變數識別碼。

下列範例會產生 C2513:

// C2513.cpp
int main() {
   int = 9;   // C2513
   int i = 9;   // OK
}

這個錯誤也可能因為針對 Visual Studio .NET 2003 完成的編譯器一致性工作而產生:不再允許 typedef 的初始化。 標準不允許 typedef 的初始化,現在會產生編譯器錯誤。

// C2513b.cpp
// compile with: /c
typedef struct S {
   int m_i;
} S = { 1 };   // C2513
// try the following line instead
// } S;

替代方式是刪除 typedef 以使用匯總初始化運算式清單來定義變數,但不建議這麼做,因為它會建立與類型名稱相同的變數,並隱藏類型名稱。