编译器错误 C2061

更新:2007 年 11 月

错误消息

语法错误: 标识符“identifier”

编译器发现了不应在此出现的标识符。请确保在使用 identifier 之前对其进行声明。

初始值设定项可能括在了括号中。为避免该问题,请将声明符括在括号中或使其成为 typedef。

在编译器将表达式作为类模板参数检测时也可能导致此错误;使用 typename 告诉编译器它是一个类型。

下面的示例生成 C2061:

// C2061.cpp
// compile with: /c
template < A a >   // C2061
// try the following line instead
// template < typename b >
class c{};

如果将实例名传递该 typeid 则会发生 C2061:

// C2061b.cpp
// compile with: /clr
ref struct G {
   int i;
};

int main() {
   G ^ pG = gcnew G;
   System::Type ^ pType = typeid<pG>;   // C2061
   System::Type ^ pType2 = typeid<G>;   // OK
}