expected primary-expression before ‘*’ token
-
wrote on 3 May 2017, 19:01 last edited by Chris Kawa 5 May 2017, 17:50
As I understand it, in c++ protected virtual member functions are designed to be overridden; however, I cannot get past the compile error. I believe that I have followed the rules exactly. What am I doing wrong?
I get the following message when I try to execute a method of the base class, namely:
expected primary-expression before ‘*’ token
QTextEdit::keyPressEvent(QKeyEvent *e)
^header
#include <QMainWindow> #include <QObject> #include <QWidget> #include <QTextEdit> #include <QKeyEvent> class FormulaEditor : public QTextEdit { Q_OBJECT public: explicit FormulaEditor(QWidget *parent = 0); void keyPressEvent(QKeyEvent * e) override ; };
source
#include "formulaeditor.h" #include <QDebug> #include <QKeyEvent> #include <QTextEdit> FormulaEditor::FormulaEditor(QWidget *parent) : QTextEdit(parent){} void FormulaEditor::keyPressEvent(QKeyEvent *e) { qDebug() << "Key Press Event " << e; if (e->key() == Qt::Key_ParenLeft) { qDebug() << "Left Parenthesis"; } QTextEdit::keyPressEvent(QKeyEvent *e); e->ignore(); }
(Chris Kawa) Edit: added code formatting tags
-
When calling a function you shouldn't specify the argument types again:
void FormulaEditor::keyPressEvent(QKeyEvent *e) { ... QTextEdit::keyPressEvent(QKeyEvent *e); // <-- here's the problem e->ignore(); }
Should be:
void FormulaEditor::keyPressEvent(QKeyEvent *e) { ... QTextEdit::keyPressEvent(e); e->ignore(); }
-
When calling a function you shouldn't specify the argument types again:
void FormulaEditor::keyPressEvent(QKeyEvent *e) { ... QTextEdit::keyPressEvent(QKeyEvent *e); // <-- here's the problem e->ignore(); }
Should be:
void FormulaEditor::keyPressEvent(QKeyEvent *e) { ... QTextEdit::keyPressEvent(e); e->ignore(); }
wrote on 5 May 2017, 18:41 last edited byI know. A very stupid mistake:
QTextEdit::keyPressEvent(QKeyEvent *e); is a prototype definition, while
QTextEdit::keyPressEvent(e); calls the function for execution.
When I discovered what I had done I marked this post as solved to cover up my stupidity, then thoroughly chastised myself.
-
No worries. Happens sometimes.
1/4