If you really want to use templated operator() and want to avoid writing constructs like a.operator()<int>(); , you can add an auxiliary parameter to it:
template <typename T> struct type{}; struct A { template<typename T> void operator()(type<T>) { } }; int main() { A a; a(type<int>()); }
Live demo .
In C ++ 14, you can even omit empty brackets in a(type<int>()); using the variable template:
template <typename T> struct type_{}; template <typename T> constexpr type_<T> type{}; struct A { template<typename T> void operator()(type_<T>) { } }; int main() { A a; a(type<int>); }
Live demo .
Constructor
source share