基类有一个指针QChart *m_chart
。在派生类中,它必须具有QPolarChart
派生自QChart
. 基类和派生类都可以访问此字段。覆盖构造函数的正确方法是什么,以便m_chart
使用 type 构造派生类中的字段QPolarChart
,同时替换基类构造函数构造的值?
class PlotView : public QAbstractItemView
{
Q_OBJECT
public:
explicit PlotView(QWidget *parent = nullptr);
~PlotView();
protected:
QChart *m_chart;
QChartView m_chartView;
};
PlotView::PlotView(QWidget *parent) :
QAbstractItemView(parent),
m_chart(new QChart),
m_chartView(m_chart)
{
}
class PolarPlotView : public PlotView
{
Q_OBJECT
public:
explicit PolarPlotView(QWidget *parent = nullptr);
};
PolarPlotView::PolarPlotView(QWidget *parent) :
PlotView(parent),
m_chart(new QPolarChart)//?
{
}
遗产