【发布时间】:2016-10-13 11:01:14
【问题描述】:
是否可以执行以下操作:
我的基类有 3 个纯虚函数。我的派生类实现了这些虚函数中的 2 个,并继承自另一个实现最终第 3 个虚函数的类。
我当前的代码无法编译,所以我认为这是无效的?虽然如果我能以某种方式使用这种方法会很棒。以下是我对这种方法的实际应用/使用。
对我可以用来实现此功能的不同方法有什么建议吗?
class ListBox
{
public:
virtual void onScroll() = 0;
virtual void foo() = 0;
virtual void bar() = 0;
};
class DragScrollHandler
{
public:
void onScroll()
{
...
}
};
class HorzListBox: public ListBox, public DragScrollHandler // could also do public HoverScrollHandler, etc.
{
public:
void foo() override
{
printf("foo\n");
}
void bar() override
{
printf("foo\n");
}
HorzListBox()
: ListBox(), DragScrollHandler()
{
}
};
【问题讨论】:
标签: c++ c++11 multiple-inheritance