Is it possible to supply template parameters when calling operator()?

Posted by Paul on Stack Overflow See other posts from Stack Overflow or by Paul
Published on 2014-08-20T16:08:59Z Indexed on 2014/08/20 16:20 UTC
Read the original article Hit count: 134

I'd like to use a template operator() but am not sure if it's possible. Here is a simple test case that won't compile. Is there something wrong with my syntax, or is this simply not possible?

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

int main() {
  A a;
  a.f<int>();           // This compiles.
  a.operator()<int>();  // This compiles.
  a<int>();             // This won't compile.
  return 0;
}

© Stack Overflow or respective owner

Related posts about c++

Related posts about templates