如何解决 C++ 中的接口方法和基类方法名称冲突建筑商?
我有以下抽象基类 SettingsInterface,将其用作接口:
class SettingsInterface
{
public:
virtual void Refresh() = 0;
virtual void Update() = 0;
virtual void OnConnect() = 0;
virtual void OnDisconnect() = 0;
};
我试图在下面的类中实现此接口,该类继承自 TFrame。 TFrame 继承自另一个类,该类也有一个名为 Update 的虚拟方法。
class DebugSettingsFrame : public TFrame, public SettingsInterface
{
//a bunch of IDE-managed components - left out for brevity
public:
virtual void Refresh();
virtual void Update();
virtual void OnConnect();
virtual void OnDisconnect();
};
当我编译它时,我收到错误虚拟函数 DebugSettingsFrame::Update() 与基类“TWinControl”冲突。 我对此感到很困惑。如何在不将接口的方法定义 Update 更改为其他内容的情况下解决此问题?
编辑 - 后续:
那么 C++ 没有类似于 C# 的构造,您可以在其中显式实现具有相同定义的接口方法吗?
谢谢!
I have the following abstract base class, SettingsInterface, that I use as an interface:
class SettingsInterface
{
public:
virtual void Refresh() = 0;
virtual void Update() = 0;
virtual void OnConnect() = 0;
virtual void OnDisconnect() = 0;
};
I'm trying to implement this interface in my class below, which inherits from TFrame. TFrame inherits from another class that also has a virtual method called Update.
class DebugSettingsFrame : public TFrame, public SettingsInterface
{
//a bunch of IDE-managed components - left out for brevity
public:
virtual void Refresh();
virtual void Update();
virtual void OnConnect();
virtual void OnDisconnect();
};
When I compile this, I get the error virtual function DebugSettingsFrame::Update() conflicts with base class 'TWinControl'.
I'm stomped on this. How can I resolve this without changing my interface's method definition, Update, to something else?
Edit - Follow-up:
So C++ doesn't have a construct similar to C# where you can explicitly implement interface methods that have the same definition?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试类似的方法(从代码中我不能准确地说出):
DebugSettingsFrame::TFrame::Update();
:: 是范围解析运算符。您应该能够准确指定您正在调用的函数的版本。
但请注意,这是设计可能变得过于复杂的症状。
Try something like (from the code I can't say exactly):
DebugSettingsFrame::TFrame::Update();
:: is the scope resolution operator. You should be able to specify precisely which version of the function you are calling.
However, note that this is a symptom of a design that may be getting too complex.