我有以下类结构:
class MyBase
{
public:
virtual ExportData exportData() = 0;
virtual bool exportData(QString filepath)
{
ExportData data = exportData();
data.save(filepath);
}
};
class MyClass : public MyBase
{
public:
virtual ExportData exportData(){//some implementation}
};
class MySubClass : public MyClass
{
public:
virtual ExportData exportData(){//some implementation}
};
然后我按如下方式导出数据:
MySubClass *sub = new MySubClass();
sub->exportData("/home/me/export.xml");
尝试使用g ++编译时,出现以下错误:
error: no matching function for call to ‘MySubClass::exportData(QString)’
note: candidate is: virtual ExportData MySubClass::exportData()
note: candidate expects 0 arguments, 1 provided
我没有看到我做错了什么,为什么会这样?
答案 0 :(得分:3)
答案 1 :(得分:1)
在virtual ExportData exportData()
中声明MySubClass
,您隐藏了virtual bool exportData(QString filepath)
。您需要使用using
声明将其带入范围:
class MySubClass : public MyClass
{
public:
using MyBase::exportData;
virtual ExportData exportData(){//some implementation}
};