共用方式為


編譯器錯誤 C2955

'identifier': 使用類別樣板或別名泛型需要範本或泛型引數清單

備註

若沒有範本或泛型引數清單,您無法使用類別樣板或泛型類別做為識別項。

如需詳細資訊,請參閱 類別範本

範例

下列範例會產生 C2955,並示範如何修正它:

// C2955.cpp
// compile with: /c
template<class T>
class X {};

X x1;   // C2955
X<int> x2;   // OK - this is how to fix it.

嘗試在類別樣板中宣告函式的行外定義時,也會發生 C2955:

// C2955_b.cpp
// compile with: /c
template <class T>
class CT {
public:
   void CTFunc();
   void CTFunc2();
};

void CT::CTFunc() {}   // C2955

// OK - this is how to fix it
template <class T>
void CT<T>::CTFunc2() {}

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

// C2955_c.cpp
// compile with: /clr
generic <class T>
ref struct GC {
   T t;
};

int main() {
   GC^ g;   // C2955
   GC <int>^ g;
}

Visual Studio 2017 和更新版本: 編譯程式會在範本參數清單中出現範本時正確診斷遺漏的範本自變數清單(例如,作為默認範本自變數或非類型範本參數的一部分)。 下列程式碼是在 Visual Studio 2015 中編譯,但在 Visual Studio 2017 中產生錯誤。

template <class T> class ListNode;
template <class T> using ListNodeMember = ListNode<T> T::*;
template <class T, ListNodeMember M> class ListHead; // C2955: 'ListNodeMember': use of alias
                                                     // template requires template argument list

// correct:  template <class T, ListNodeMember<T> M> class ListHead;