我用gcc/4.7,我需要实例化的模板函数(或成员函数)的模板,模板参数的类。我收到以下错误模板模板代码不工作
test.cpp: In function 'void setup(Pattern_Type&)':
test.cpp:17:34: error: type/value mismatch at argument 1 in template parameter list for 'template<template<class> class C> struct A'
test.cpp:17:34: error: expected a class template, got 'typename Pattern_Type::traits'
test.cpp:17:37: error: invalid type in declaration before ';' token
test.cpp:18:5: error: request for member 'b' in 'a', which is of non-class type 'int'
通过注释标注在片段中的两行代码运行,所以一个能在“主”,但不是“设置”实例化。我想,这将是为其他人的利益,我会很高兴地理解为什么代码不起作用的原因。这里的代码
struct PT {
template <typename T>
struct traits {
int c;
};
};
template <template <typename> class C>
struct A {
typedef C<int> type;
type b;
};
template <typename Pattern_Type>
void setup(Pattern_Type &halo_exchange) {
A<typename Pattern_Type::traits> a; // Line 17: Comment this
a.b.c=10; // Comment this
}
int main() {
A<PT::traits> a;
a.b.c=10;
return 0;
}
感谢您的任何建议和修复! 莫罗
是否MSVC10下编译。 –