![](/img/trans.png)
[英]Can you pass a subclass as an argument to a function with a superclass parameter? C++
[英]Unable to pass a subclass instance as argument instead of superclass
在我的代码中,我有继承自QGraphicsScene
类McdGraphicsScene
,但是当我尝试将指向McdGraphicsScene
的实例的指针传递给QGraphicsView::setScene(QGraphicsScene* scene);
我收到以下错误:
../MeriseModeler/merisemodeler/mcdui.cpp: In member function 'void McdUi::setModel(McdModel*)':
../MeriseModeler/merisemodeler/mcdui.cpp:34:42: error: no matching function for call to 'QGraphicsView::setScene(McdGraphicsScene*)'
../MeriseModeler/merisemodeler/mcdui.cpp:34:42: note: candidate is:
In file included from ../../.qt5/5.0.0/gcc/include/QtWidgets/QGraphicsView:1:0,
from ../MeriseModeler/merisemodeler/mcdui.cpp:10:
../../.qt5/5.0.0/gcc/include/QtWidgets/qgraphicsview.h:161:10: note: void QGraphicsView::setScene(QGraphicsScene*)
../../.qt5/5.0.0/gcc/include/QtWidgets/qgraphicsview.h:161:10: note: no known conversion for argument 1 from 'McdGraphicsScene*' to 'QGraphicsScene*'
这是该类的代码
class McdGraphicsScene : public QGraphicsScene
{
Q_OBJECT
// Methods and attributs
};
你在使用McdGraphicsScene
任何前瞻声明吗?
确保在呼叫站点上可以看到实际的类定义。 如果只有前向声明可用,则调用代码不能推断出McdGraphicsScene
继承自QGraphicsScene
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.