Petit problème d'héritage
Bonjour les amis,
J'ai besoin de comprendre une petite chose concernant les listes et l'héritage.
En effet, c'est un petit problème que j'ai rencontré en utilisant Qt, mais je pense que c'est un problème C++ plutôt, d'où mon poste ici.
J'ai simplifier mon problème au maximum, j'ai une QMainwindow qui contient deux listes d'object héritant tout les deux d'une classe GraphicsView qui hérite à son tour de la class QGraphicsView. Le .h de la mainwindow est donc le suivant:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "graphicsview.h"
#include "specialview1.h"
#include "specialview2.h"
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
QList<GraphicsView*> getGraphics();
private:
QList<SpecialView1*> _graphicsS1;
QList<SpecialView2*> _graphicsS2;
bool test;
};
#endif // MAINWINDOW_H |
dans le .cpp j'ai une methode getter qui doit renvoyer une des deux liste en fonction du boolean test:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#include "mainwindow.h"
#include "graphicsview.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
test = true;
}
MainWindow::~MainWindow()
{
}
QList<GraphicsView*> MainWindow::getGraphics()
{
if( test )
return _graphicsS1;
else
return _graphicsS2;
} |
J'arrive enfin à mon problème, la compilation de ce code me donne l'erreur suivante:
Code:
1 2 3 4
|
D:\Qt\QtCreator2.4.1\Autres\mainwindow.cpp:21: erreur : conversion from 'QList<SpecialView1*>' to non-scalar type 'QList<GraphicsView*>' requested
et...
D:\Qt\QtCreator2.4.1\Autres\mainwindow.cpp:24: erreur : conversion from 'QList<SpecialView2*>' to non-scalar type 'QList<GraphicsView*>' requested |
j'aimerais comprend pourquoi cette erreur, pour je suis obliger de faire la conversion à la main!?
Merci d'avance pour votre aide :)