Calling a templated base class method compile fails
I am attempting to call a templated base class method through a derived class. This is my code
struct base
{
template<typename t>
void baseMethod(t s)
{
std::cout << s;
}
};
struct der : public base
{
};
int main()
{
der d;
d.<int>(baseMethod(12));
}
The compilation fails and states
main.cpp: In function 'int main()': main.cpp:25:5: error: expected unqualified-id before '<' token d.(baseMethod(12)); ^ main.cpp:25:6: error: expected primary-expression before 'int' d.(baseMethod(12));
Any suggestions on how I can fix it ?
Notwithstanding the fact that this questuion has nothing to do with the inheritance, the proper syntax would be
d.baseMethod<int>(12);
However, even this is not needed due to template deduction: simple
d.baseMethod(12);
would work.
链接地址: http://www.djcxy.com/p/59566.html上一篇: 具有任何参数的模板仿函数
下一篇: 调用模板化的基类方法编译失败