共用方式為


編譯器錯誤 C2902

'token' :未預期的令牌遵循 'template',必須是標識符

備註

關鍵字 template 後面的語彙基元不是識別項。

在 Visual Studio 2022 和更新版本中,此錯誤已經過時。

範例

下列範例會產生 C2902:

// C2902.cpp
// compile with: /c
namespace N {
   template<class T> class X {};
   class Y {};
}
void g() {
   N::template + 1;   // C2902
}

void f() {
   N::template X<int> x1;   // OK
}

使用泛型時,也會發生 C2902:

// C2902b.cpp
// compile with: /clr /c
namespace N {
   generic<class T> ref class GC {};
}

void f() {
   N::generic + 1;   // C2902
   N::generic GC<int>^ x;
}