1

To put it somewhat vaguely, from the snippet (tt.cc) below it seems to me as if the template template notion lacked some kind of a "transparency". While I don't seem to fathom what other template argument should A::f() be provided (besides the template template one), I might as well be just missing some banality here.

template <class T>
class A {
public:
  template< template<class> class U >
  void f( int i ) {
    // ...
  }
};


template< class T, template<class> class U >
class B {
public:
  void f( int i ) {
    A<T> a;
    a.f<U>( i );
  }
};


int main() {
  return 0;
}

The error message it provides is:

g++ ./tt.cc -o tt
./tt.cc: In member function ‘void B<T, U>::f(int)’:
./tt.cc:17:10: error: missing template arguments before ‘>’ token
     a.f<U>( i );
          ^
Compilation exited abnormally with code 1

Any ideas greatly appreciated.

calmity
  • 113
  • 1
  • 9

1 Answers1

3

What you are seeing is the compiler interpreting the > token inside f<U> as the inequality operator. You need to add .template to let the compiler know you mean a template argument.

  void f( int i ) {
    A<T> a;
    a.template f<U>( i );
  }

Live Example.

See also Where and why do I have to put the “template” and “typename” keywords?.

Community
  • 1
  • 1
TemplateRex
  • 69,038
  • 19
  • 164
  • 304