我不知道这是否可能: 可以说我有一个定义的接口(interface):
virtual void func()=0;
是否有可能在具体类中我像下面这样覆盖它:
template <std::size_t number>
void func(){ /* do something with number... */ }
谢谢!
最佳答案
is it possible that in the concrete class I override it like the following :
不,那行不通。
想想这个案例。
struct Base
{
virtual void func()=0;
};
struct Derived : Base
{
template <std::size_t number>
void func(){}
};
和
Base* b = new Derived;
b->func(); // Which of the Derived::func() should that resolve to at run time?
// Derived::func<0>()?
// Derived::func<10>()?
// ...
这在概念上根本没有意义。
关于c++ - 是否可以将纯虚函数覆盖到模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52887834/