我有多重继承的问题。C++中的多重继承(Qt示例)
我想要一个类IEdge来实现QGraphicsItem“接口”,它包含了boundindRect()和paint(...)抽象方法。 IEdge还添加了一些新的方法。
class IEdge : public QGraphicsItem
{
public:
virtual Vertex * getVertex1() = 0;
virtual Vertex * getVertex2() = 0;
}
现在我想创建UndirectedEdge,延伸IEdge,但我不想由我自己来实现boundingRect()和paint(...),我想使用IQGraphicsLineItem实施。
class UndirectedEdge : public IEdge, public IGraphicsLineItem
{
public:
virtual Vertex* getVertex1();
virtual Vertex* getVertex2();
}
但是,这并不工作,编译器说,UndirectedEdge是抽象的,因为boundingRect()和paint(...)没有实现(但我敢肯定的是,IGraphicsLineItem包含这些方法)。我不知道,为什么它不起作用。非常感谢你的解释。
编辑:
我能解决这个问题,但我只是好奇。在我的主要语言的C#它会工作,我错过了一些重要的继承在C + + :-(一些提示,将不胜感激,谢谢
感谢您的解决方案,但我只是好奇,为什么它不工作。我确信它会在C#中完美工作:)我错过了C++中的继承关系:-( – bidacek 2013-03-13 00:20:34
编译器知道IEdge :: boundingRect()和IGraphicsLineItem :: boundingRect()之间的区别......它们不是即使部分签名拼写相同,也是如此。 – Bill 2013-03-13 16:35:30