Używam gcc/4.7 i potrzebuję utworzyć instancję klasy z argumentem szablonu szablonu w funkcji szablonu (lub funkcji członka). Otrzymuję następujący błądKod szablonu szablonu nie działa
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'
komentując dwie linie oznaczone we fragmencie uruchamia kod, więc A a może być instancja w „głównym”, ale nie w „setup”. Myślę, że byłoby to interesujące także dla innych osób i byłbym naprawdę szczęśliwy mogąc zrozumieć powód, dla którego kod nie działa. Oto kod
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;
}
Dzięki za wszelkie sugestie i poprawki! Mauro
Kompiluje pod MSVC10. –