Solved C2142: syntax error: missing ';' before '*'
-
I'm using MSVC2015 with Qt 5.9.2, I've added a new classes to my project, still very much a work in progress but I'm getting some strange error message which I just can't track down the cause.
Abstract class prototype of MsgDecoder
#ifndef MSGDECODER_H #define MSGDECODER_H #include <QJsonObject> #include <QObject> #include <QMap> #include <QString> class MsgDecoder; typedef QMap<QString, MsgDecoder*> tMsgTypesMap; typedef enum { D_NOT_FOUND = 0, D_TRAINEE, D_TRAINER } eDestination; class MsgDecoder : public QObject { Q_OBJECT private: const QString mcstrMsgType; eDestination meDest; static tMsgTypesMap msmpMsgTypes; public: MsgDecoder(const QString& crstrMsgType, const eDestination ceDest); virtual bool blnDecode(const QJsonObject& crobjMsg) = 0; QString cstrMsgType() const { return mcstrMsgType; } static bool blnDecodeMsgByType(const QString& crstrMsgType, const QJsonObject& crobjMsg); eDestination eDest() { return meDest; } static eDestination getDestFromMsg(const QJsonObject& crobjMsg); static eDestination getDestFromMsg(const QString& crstrMsg); static eDestination getDestFromMsgType(const char* cpszMsgType); signals: void error(const QString& crstrErrorMsg); }; #endif // MSGDECODER_H
This class is derived from the above:
#ifndef HEARTBEAT_H #define HEARTBEAT_H #include <QMetaObject> #include <QTimer> #include "msgdecoder.h" #include "sckcomms.h" class HeartbeatMsg : public MsgDecoder { Q_OBJECT private: static QMetaObject::Connection mscnnTimeout; static const quint16 mscuint16Heartbeat; static const quint16 mscuint16Timeout; static qint16 msint16HeartbeatCtr; static QTimer* msptmrTimeout; public: HeartbeatMsg(); ~HeartbeatMsg(); virtual bool blnDecode(const QJsonObject &crobjMsg); static void nonServerChecks(const QString& crstrMsgType); static void service(bool* pblnMsgSent = nullptr); static void setupHeartbeat(); signals: void heartbeatTimeout(); }; #endif // HEARTBEAT_H
In another class I try to define an instance of the HeartbeatMsg:
QMetaObject::Connection mcnnStatusAbort; HeartbeatMsg* mpHeartbeat;
The file where this definition exists includes the header that has the HeartbeatMsg prototype, but when I try to compile the project I get the error message:
C2142: syntax error: missing ';' before '*'
I can see nothing wrong with the line or the lines above it, if I click the error it takes me directly to the line:
HeartbeatMsg* mpHeartbeat;
Hovering over the line results in:
C2143: syntax error: missing ';' before '*' C4430: missing type specifier - int assumed. Note C++ does not support default-int C2238: unexpected token(s) preceding ';'
I've looked at the source and I cannot see what is causing this.
-
@JonB , I think I've found it and like most issues, it was actually nothing to do with the display error messages. In a completely unrelated bit of the source there was a missing ')' at the end of a line.
-
@SPlatten
At least give us a couple of lines of context immediately above the faulting
HeartbeatMsg* mpHeartbeat;
line!Also try
HeartbeatMsg temp;
and report what the error reads? Is that the same message as
Rubbish temp;
? -
@JonB , I just modified the same header adding:
HeartbeatMsg mHeartbeat;
The errors:
C3646: 'mHeartbeat': unknown override specifier C4430: missing type specifier - int assumed. Note C++ does not support default-int
-
@JonB , I think I've found it and like most issues, it was actually nothing to do with the display error messages. In a completely unrelated bit of the source there was a missing ')' at the end of a line.