Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. C2142: syntax error: missing ';' before '*'
Forum Updated to NodeBB v4.3 + New Features

C2142: syntax error: missing ';' before '*'

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1

    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.

    Kind Regards,
    Sy

    JonBJ 1 Reply Last reply
    0
    • JonBJ JonB

      @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;
      ?

      SPlattenS Offline
      SPlattenS Offline
      SPlatten
      wrote on last edited by
      #4

      @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.

      Kind Regards,
      Sy

      1 Reply Last reply
      0
      • SPlattenS SPlatten

        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.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #2

        @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;
        ?

        SPlattenS 1 Reply Last reply
        0
        • SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by SPlatten
          #3

          @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
          

          Kind Regards,
          Sy

          1 Reply Last reply
          0
          • JonBJ JonB

            @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;
            ?

            SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by
            #4

            @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.

            Kind Regards,
            Sy

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved