编译器错误 C3206
“function”:“param”的类型参数无效,缺少对类类型“typename”上的类型参数列表
将函数模板定义为采用模板类型参数。 但是,模板模板参数被传递。
以下示例生成 C3206:
// C3206.cpp
template <class T>
void f() {}
template <class T>
struct S {};
void f1() {
f<S>(); // C3206
// try the following line instead
// f<S<int> >();
}
可能的解决方法:
// C3206b.cpp
// compile with: /c
template <class T>
void f() {}
template <class T>
struct S {};
void f1() {
f<S<int> >();
}
使用泛型时,也可能发生 C3206:
// C3206c.cpp
// compile with: /clr
generic <class GT1>
void gf() {}
generic <class T>
value struct GS {};
int main() {
gf<GS>(); // C3206
}
可能的解决方法:
// C3206d.cpp
// compile with: /clr
generic <class GT1>
void gf() {}
generic <class T>
value struct GS {};
int main() {
gf<GS<int> >();
}
不允许类模板作为模板类型参数。 以下示例引发 C3206:
// C3206e.cpp
template <class T>
struct S {};
template <class T>
void func() { // takes a type
T<int> t;
}
int main() {
func<S>(); // C3206 S is not a type.
}
可能的解决方法:
// C3206f.cpp
template <class T>
struct S {};
template <class T>
void func() { // takes a type
T t;
}
int main() {
func<S<int> >();
}
如果需要模版参数,则必须将函数包装在接受模版参数的模板类中:
// C3206g.cpp
template <class T>
struct S {};
template<template<class> class TT>
struct X {
static void func() {
TT<int> t1;
TT<char> t2;
}
};
int main() {
X<S>::func();
}