共用方式為


編譯器錯誤 C2970

'class' : 樣板參數 'param' : 'arg' : 涉及具有內部連結之物件的表達式不能當做非類型自變數使用

您無法使用靜態變數的名稱或地址作為範本自變數。 樣板類別需要可在編譯時期評估的 const 值。

下列範例會產生 C2970:

// C2970.cpp
// compile with: /c
static int si;
// could declare nonstatic to resolve all errors
// int si;

template <int i>
class X {};

template <int *pi>
class Y {};

X<si> anX;   // C2970 cannot use static variable in templates

// this would also work
const int i = 10;
X<i> anX2;