gpt4 book ai didi

c++ - 无法将子类实例作为参数而不是父类(super class)传递

转载 作者:太空狗 更新时间:2023-10-29 20:05:06 24 4
gpt4 key购买 nike

在我的代码中,我有继承自 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
};

最佳答案

您是否使用任何 forward declarations McdGraphicsScene

确保实际的类定义在调用站点可见。如果只有前向声明可用,则调用代码无法推断出 McdGraphicsScene 继承自 QGraphicsScene

关于c++ - 无法将子类实例作为参数而不是父类(super class)传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15247318/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com