需要一些关于模板成员函数专业化的帮助,如下代码所示;
class Base
{
public:
template <int> void MyFunc();
};
class Object : public Base
{
public:
//template <int> void MyFunc(); // with this works !!!
template <> void MyFunc<3>()
{
}
};谢谢!
发布于 2022-11-13 23:41:01
你不能这么做。
原因是当编译器看到对象的声明时,它对Base的模板函数一无所知。因此,它不能为对象生成MyFunc的专门化。
使此工作的唯一方法是在基类中声明MyFunc的专门化。
成员函数模板不被继承。
https://stackoverflow.com/questions/74425494
复制相似问题