Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ template syntax

Tags:

c++

templates

How do I fix this syntax error?

struct A {
  template < typename T >
  void f () {}
};

template < typename C, typename U >
struct B {
  void g () {
    U::f < C > ();   // expected primary-expression before »>« token
  }
};

int main () {
  B<int,A> b;
  b.g ();
}
like image 723
Thomas Avatar asked Dec 06 '25 09:12

Thomas


1 Answers

U is a dependent type so you need to specify that f is a template member:

U::template f<C>();

This is still invalid when U is A, though, as f is not a static member of A.

like image 87
CB Bailey Avatar answered Dec 08 '25 22:12

CB Bailey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!