M
maxgross
Hi everyone,
ive got a problem with polymorphism. When i compile the code an error
occures:
error: 'class QtElement' has no member named 'DisplayQtElement'
I asked my friends and nobody could help me, all said it has to work.
I work with wxWidgets 2.6.3 under Linux.
Structure of classes:
wxTreeItemData->QtElement->StructureElement->Assessment
wxTreeItemData->QtElement->StructureElement->Section
wxTreeItemData->QtElement->QuestionElement->MultipleChoice
wxTreeItemData->QtElement->QuestionElement->MultipleResponse
QtElement, StructureElement, QuestionElement are abstract classes.
Here the code:
---------------------------------------------------------------------------------------------
#ifndef QT_ELEMENT_H_
#define QT_ELEMENT_H_
#include <wx/treectrl.h>
class QtElement: public wxTreeItemData
{
protected:
QtElement(NativeString title) :title(title) {}
NativeString title;
public:
virtual void DisplayQtElement() = 0;
virtual NativeString GetTitle() { return title; }
virtual ~QtElement() {}
};
#endif /*QT_ELEMENT_H_*/
---------------------------------------------------------------------------------------------
#ifndef QUESTION_ELEMENT_H_
#define QUESTION_ELEMENT_H_
#include "qt_element.h"
class QuestionElement : public QtElement
{
protected:
QuestionElement(NativeString title, NativeString qText)
: QtElement(title), questionText(qText) {}
NativeString questionText;
public:
virtual ~QuestionElement() {}
virtual NativeString GetQuestionText() { return questionText; }
};
#endif /*QUESTION_ELEMENT_H_*/
---------------------------------------------------------------------------------------------
#ifndef MULTIPLE_RESPONSE_H_
#define MULTIPLE_RESPONSE_H_
#include "question_element.h"
class MultipleResponse: public QuestionElement
{
public:
MultipleResponse(NativeString title, NativeString qText)
: QuestionElement("MultipleResponse", title, qText) {}
virtual ~MultipleResponse() {}
virtual void DisplayQtElement();
private:
};
inline void
MultipleResponse:isplayQtElement()
{
// display element
}
#endif /*MULTIPLE_RESPONSE_H_*/
---------------------------------------------------------------------------------------------
Usage:
---------------------------------------------------------------------------------------------
....
wxTreeCtrl qtTree = new wxTreeCtrl(this, ID_TREE_CTRL,
wxDefaultPosition, wxSize(100,300),wxTR_SINGLE | wxTR_HIDE_ROOT |
wxTR_FULL_ROW_HIGHLIGHT | wxTR_HAS_BUTTONS);
QtElement *qe = new MultipleChoice(title,q_text);
qtTree->AppendItem(parent, title, -1, -1,
dynamic_cast<wxTreeItemData*>(qe));
....
QtElement *qt =
dynamic_cast<QtElement*>(qtTree->GetItemData(selection));
// if i cast to QuestionElement, StructureElement or the conrete
classes then it to works
qt->DisplayQtElement(); // error
qt->GetTitle(); // is working
---------------------------------------------------------------------------------------------
I have to derive QtElement from wxTreeItemData so that i can add a
QtElement to the wxTreeCtrl.
Perhaps someone can help me, thanks.
Max
ive got a problem with polymorphism. When i compile the code an error
occures:
error: 'class QtElement' has no member named 'DisplayQtElement'
I asked my friends and nobody could help me, all said it has to work.
I work with wxWidgets 2.6.3 under Linux.
Structure of classes:
wxTreeItemData->QtElement->StructureElement->Assessment
wxTreeItemData->QtElement->StructureElement->Section
wxTreeItemData->QtElement->QuestionElement->MultipleChoice
wxTreeItemData->QtElement->QuestionElement->MultipleResponse
QtElement, StructureElement, QuestionElement are abstract classes.
Here the code:
---------------------------------------------------------------------------------------------
#ifndef QT_ELEMENT_H_
#define QT_ELEMENT_H_
#include <wx/treectrl.h>
class QtElement: public wxTreeItemData
{
protected:
QtElement(NativeString title) :title(title) {}
NativeString title;
public:
virtual void DisplayQtElement() = 0;
virtual NativeString GetTitle() { return title; }
virtual ~QtElement() {}
};
#endif /*QT_ELEMENT_H_*/
---------------------------------------------------------------------------------------------
#ifndef QUESTION_ELEMENT_H_
#define QUESTION_ELEMENT_H_
#include "qt_element.h"
class QuestionElement : public QtElement
{
protected:
QuestionElement(NativeString title, NativeString qText)
: QtElement(title), questionText(qText) {}
NativeString questionText;
public:
virtual ~QuestionElement() {}
virtual NativeString GetQuestionText() { return questionText; }
};
#endif /*QUESTION_ELEMENT_H_*/
---------------------------------------------------------------------------------------------
#ifndef MULTIPLE_RESPONSE_H_
#define MULTIPLE_RESPONSE_H_
#include "question_element.h"
class MultipleResponse: public QuestionElement
{
public:
MultipleResponse(NativeString title, NativeString qText)
: QuestionElement("MultipleResponse", title, qText) {}
virtual ~MultipleResponse() {}
virtual void DisplayQtElement();
private:
};
inline void
MultipleResponse:isplayQtElement()
{
// display element
}
#endif /*MULTIPLE_RESPONSE_H_*/
---------------------------------------------------------------------------------------------
Usage:
---------------------------------------------------------------------------------------------
....
wxTreeCtrl qtTree = new wxTreeCtrl(this, ID_TREE_CTRL,
wxDefaultPosition, wxSize(100,300),wxTR_SINGLE | wxTR_HIDE_ROOT |
wxTR_FULL_ROW_HIGHLIGHT | wxTR_HAS_BUTTONS);
QtElement *qe = new MultipleChoice(title,q_text);
qtTree->AppendItem(parent, title, -1, -1,
dynamic_cast<wxTreeItemData*>(qe));
....
QtElement *qt =
dynamic_cast<QtElement*>(qtTree->GetItemData(selection));
// if i cast to QuestionElement, StructureElement or the conrete
classes then it to works
qt->DisplayQtElement(); // error
qt->GetTitle(); // is working
---------------------------------------------------------------------------------------------
I have to derive QtElement from wxTreeItemData so that i can add a
QtElement to the wxTreeCtrl.
Perhaps someone can help me, thanks.
Max