专门的虚拟方法 class

Virtual method of a specialized class

是否可以在已经特化的class上定义虚方法?例如

template
<class T_DataType>
struct Interface
{
T_DataType data;
...
};

struct NewInterface : Interface<int>
{
virtual
int return_data() = 0;
...
}

struct SubInterface : NewInterface
{
virtual
int return_data();
...
}

int SubInterface::return_data(){ return data;}

是的,代码有效且按预期工作。

在这种情况下,您没有特化 SubInterface,而是从模板特化中继承它。