我正在尝试从旧类派生一个新类。基类声明如下所示:
class Driver : public Plugin, public CmdObject
{
protected:
Driver();
public:
static Driver* GetInstance();
virtual Engine& GetEngine();
public:
// Plugin methods...
virtual bool InitPlugin (Mgr* pMgr);
virtual bool Open();
virtual bool Close();
// CmdObject
virtual bool ExecObjCmd(uint16 cmdID, uint16 nbParams, CommandParam *pParams, CmdChannelError& error);
Mgr *m_pMgr;
protected:
Services *m_pServices;
Engine m_Engine;
};
它的构造函数如下所示:
Driver::Driver() :
YCmdObject("Driver", (CmdObjectType)100, true),
m_Engine("MyEngine")
{
Services *m_pServices = NULL;
Mgr *m_pMgr = NULL;
}
因此,当我创建派生类时,我首先尝试简单地从基类继承:
class NewDriver : public Driver
并复制构造函数:
NewDriver::NewDriver() :
CmdObject("NewDriver", (EYCmdObjectType)100, true),
m_Engine("MyNewEngine")
{
Services *m_pServices = NULL;
Mgr *m_pMgr = NULL;
}
编译器(来自 Analog Devices 的 VisualDSP++ 5.0)不喜欢这样:
".\NewDriver.cpp", line 10: cc0293: error: indirect nonvirtual base
class is not allowed
CmdObject("NewDriver", (EYCmdObjectType)100, true),
这是有道理的,所以我决定直接从 Plugin 和 CmdObject 继承。为了避免多重继承歧义问题(我想),我使用了虚拟继承:
class NewDriver : public Driver, public virtual Plugin, public virtual CmdObject
但是随后,在 NewDriver 中实现虚拟方法时,我尝试调用采用 Plugin* 的 Mgr::RegisterPlugin 方法,结果如下:
".\NewDriver.cpp", line 89: cc0286: error: base class "Plugin" is
ambiguous
if (!m_pMgr->RegisterPlugin(this))
this 指针如何模棱两可,我该如何解决?
谢谢,
——保罗