I don't understand why the following code isn't working, why can't I explicitly instantiate the templated function? If I remove that < int > I get a "no matching function call"
#include <iostream>
using namespace std;
template <typename T>
class Xclass
{
public:
template <typename Y>
void xfunc()
{
cout << "Hello";
}
};
template<typename T2>
class Z
{
public:
void x2()
{
Xclass<T2> obj;
obj.xfunc<int>();
}
};
int main() {
Z<int> obj;
obj.x2();
return 0;
}
The error is:
prog.cpp: In member function ‘void Z<T2>::x2()’:
prog.cpp:24:15: error: expected primary-expression before ‘int’
obj.xfunc<int>();
^
prog.cpp:24:15: error: expected ‘;’ before ‘int’