Template template template does not work

I am using gcc / 4.7 and I need to create an instance of the class with the template template argument in the template function (or member function). I get the following error

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' 

After commenting on the two lines marked in the code fragment, the code is executed, so A a can be created in "main", but not in "setup". I think it will be interesting for others as well, and I would be very happy to understand the reason why the code does not work. Here is the code

 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 abc=10; // Comment this } int main() { A<PT::traits> a; abc=10; return 0; } 

Thanks for any suggestion and fix! Mauro

+6
source share
1 answer

You need to mark Pattern_Type::traits as a pattern:

 A<Pattern_Type::template traits> a; 

This is necessary because it depends on the Pattern_Type template Pattern_Type .

You should also not use typename there, because traits is a template, not a type.

+9
source

All Articles