編譯器警告 (層級 1 和層級 2) C4091

'keyword': 當沒有宣告變數時,忽略 'type' 的左方

編譯器偵測到使用者可能打算宣告變數的情況,但編譯器無法宣告變數。

範例

使用者定義類型宣告開頭的 __declspec 屬性會套用至該類型的變數。 C4091 表示未宣告任何變數。 下列範例會產生 C4091。

// C4091.cpp
// compile with: /W1 /c
__declspec(dllimport) class X {}; // C4091

// __declspec attribute applies to varX
__declspec(dllimport) class X2 {} varX;

// __declspec attribute after the class or struct keyword
// applies to user defined type
class __declspec(dllimport) X3 {};

如果標識碼是 typedef,則它不能也是變數名稱。 下列範例會產生 C4091。

// C4091_b.cpp
// compile with: /c /W1 /WX
#define LIST 4
typedef struct _LIST {} LIST;   // C4091