Greetings to all
I come from the Java background, and I am having difficulty with multiple inheritance.
I have an interface called IView that has an init () method. I want to get a new class called PlaneViewer that implements the above interface and extends another class. (QWidget).
My implementation is as follows:
IViwer.h (header file only, not CPP file):
#ifndef IVIEWER_H_ #define IVIEWER_H_ class IViewer { public:
My derived class.
PlaneViewer.h
#ifndef PLANEVIEWER_H #define PLANEVIEWER_H #include <QtGui/QWidget> #include "ui_planeviewer.h" #include "IViewer.h" class PlaneViewer : public QWidget , public IViewer { Q_OBJECT public: PlaneViewer(QWidget *parent = 0); ~PlaneViewer(); void init(); //do I have to define here also ? private: Ui::PlaneViewerClass ui; }; #endif // PLANEVIEWER_H
PlaneViewer.cpp
#include "planeviewer.h" PlaneViewer::PlaneViewer(QWidget *parent) : QWidget(parent) { ui.setupUi(this); } PlaneViewer::~PlaneViewer() { } void PlaneViewer::init(){ }
My questions:
- Do I need to declare the init () method in the PlaneViewer interface, because it is already defined in IView?
2. I cannot execute the code above, give an error:
PlaneViewer] + 0x28): undefined reference to `typeinfo for IViewer 'collect2: ld returned 1 exit status
Should I have an implementation for IView in a CPP file (because all I want is an interface, not an implementation)?
c ++ inheritance multiple-inheritance virtual
Ashika Umanga Umagiliya
source share