编译器错误 C3855

“class”:类型参数“param”与声明不兼容

编译器发现了具有不同名称的非类型模板或泛型参数。 在模板专用化的定义中的指定模板参数与其声明不兼容时,可能会发生这种情况。

下面的示例生成 C3855:

// C3855.cpp
template <int N>
struct C {
   void f();
};

template <char N>
void C<N>::f() {}   // C3855

可能的解决方法:

// C3855b.cpp
// compile with: /c
template <int N>
struct C {
   void f();
};

template <int N>
void C<N>::f() {}

在使用泛型时也可能发生 C3855:

// C3855c.cpp
// compile with: /clr
generic <class T>
ref struct GC1 {
   generic <class U>
   ref struct GC2;
};

generic <class T>
generic <class U>
generic <class V>
ref struct GC1<T>::GC2 { };   // C3855

可能的解决方法:

// C3855d.cpp
// compile with: /clr /c
generic <class T>
ref struct GC1 {
   generic <class U>
   ref struct GC2;
};

generic <class T>
generic <class U>
ref struct GC1<T>::GC2 { };