Code:
#include <iostream>
struct S {
template<typename T>
void method() const;
};
template<typename T>
void S::method() const {
std::cout << "Hello World\n";
}
template<typename Obj>
void func(const Obj& obj) {
obj.method<int>();
}
int main() {
S s;
func(s);
}
When I try to compile this code I get the following error:
<source>:15:16: error: expected primary-expression before 'int'
15 | obj.method<int>();
| ^~~
<source>:15:16: error: expected ';' before 'int'
15 | obj.method<int>();
| ^~~
| ;
Is there any way to call this function, if you have to explicitly specify the template argument?