好的,我有:
template<typename T>
class Reader
{
class Input
{
template<typename C>
void operator()(C& val) const
{
/* Do Some Work */
}
};
};
不幸的是,“做一些工作”的通用版本对我不起作用。它也不容易修改,因为它位于一些繁重的模板元编程代码的中间。
所以我想我可以专门针对我的类型的方法。所以我的第一步是尝试从类中提取通用方法。
template<typename T>
class Reader
{
class Input
{
template<typename C>
void operator()(C& val) const;
};
};
template<typename T>
template<typename C>
void typename Reader<T>::Input template operator()<C>(C& val) const // LINE 13
{
/* Do Some Work */
}
不幸的是我收到错误:
s.h:13: error: error: expected ‘)’ before ‘&’ token
最佳答案
照常写就可以了
template<typename T>
template<typename C>
void Reader<T>::Input::operator()(C& val) const // LINE 13
{
/* Do Some Work */
}
在类外定义通用版本并不能帮助您提供它的特殊版本,或者我确实错过了您在这里的目标。
关于c++ - Template 模板方法的特化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6527929/