Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

error: expected constructor, destructor, or type conversion before ‘enum’ while building in linux with make



  • Hi,

    I am facing below build error while building the qt project.

    /home/ravi/> make
    g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIC -DQT_WEBKIT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -std=c++11  -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -o discoverythread.o onvif/discoverythread.cpp
    In file included from onvif/discoverythread.cpp:2:0:
    ./onvif/discoveryobj.h:10:1: error: expected constructor, destructor, or type conversion before ‘enum’
     enum DiscoveryMode{
     ^
    ./onvif/discoveryobj.h:31:5: error: ‘DiscoveryMode’ does not name a type
         DiscoveryMode mode;
         ^
    ./onvif/discoveryobj.h:39:32: error: expected ‘)’ before ‘mode’
         DiscoveryObj(DiscoveryMode mode, int _metadataVersion, char* _xaddr, char* _type, char* _scope, char* _endpoint);
    ravi@134.141.242.126:/home/ravi/cprog/OnvifDiscoveryLib/>make
    g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIC -DQT_WEBKIT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -std=c++11  -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -o discoverythread.o onvif/discoverythread.cpp
    In file included from onvif/discoverythread.cpp:2:0:
    ./onvif/discoveryobj.h:10:1: error: expected constructor, destructor, or type conversion before ‘enum’
     enum DiscoveryMode{
     ^
    ./onvif/discoveryobj.h:31:5: error: ‘DiscoveryMode’ does not name a type
         DiscoveryMode mode;
         ^
    ./onvif/discoveryobj.h:39:32: error: expected ‘)’ before ‘mode’
         DiscoveryObj(DiscoveryMode mode, int _metadataVersion, char* _xaddr, char* _type, char* _scope, char* _endpoint);
                                    ^
    Makefile:299: recipe for target 'discoverythread.o' failed
    make: *** [discoverythread.o] Error 1
    
    // File name: discoveryobj.h
    
    #ifndef prob_H
    #define prob_H
    
    #include <QVector>
    #include <QString>
    #include <QObject>
    #include "descdevice.h"
    #include "discoverythread.h"
    
    enum DiscoveryMode{
        SERVER_MODE, CLIENT_MODE
    };
    
    class DiscoveryObj: public QObject{
    
        Q_OBJECT   
    signals:
        void discoveredDevice(DescDevice);
    
    private:
        DiscoveryThread discoveryThread;
    
    public:
    //    const int   _metadataVersion = 1;
    //    const char* _xaddr="http://localhost/service";
    //    const char* _type="\"http://schemas.xmlsoap.org/ws/2006/02/devprof\":device";
    //    const char* _scope="scope";
    //    const char* _endpoint="urn";
    
    
        DiscoveryMode mode;
        static DiscoveryObj *theDiscovery;
        int   _metadataVersion;
        char* _xaddr;
        char* _type;
        char* _scope;
        char* _endpoint;
    
        DiscoveryObj(DiscoveryMode mode, int _metadataVersion, char* _xaddr, char* _type, char* _scope, char* _endpoint);
        ~DiscoveryObj();
    
        int sendProb();
        int sendHello();
        int sendBye();
    };
    
    #endif
    
    
    // Filename: discoverythread.h
    
    #ifndef MYTHREAD_H
    #define MYTHREAD_H
    #include <QThread>
    
    class DiscoveryThread : public QThread
    {
        const char* host = "239.255.255.250";
        int port = 3702;
    //    const int   _metadataVersion = 1;
    //    const char* _xaddr="http://localhost/service";
    //    const char* _type="\"http://schemas.xmlsoap.org/ws/2006/02/devprof\":device";
    //    const char* _scope="scope";
    //    const char* _endpoint="urn";
        Q_OBJECT
    public:
        DiscoveryThread();
    protected:
        void run();
    };
    
    #endif // MYTHREAD_H
    
    
    // File Name: descdevice.h
    
    #ifndef DESCDEVICE
    #define DESCDEVICE
    
    struct DescDevice{
        int metadataversion;
        QString types;
        QString xAddrs;
        QString scopes;
    };
    
    Q_DECLARE_METATYPE(DescDevice)
    
    #endif // DESCDEVICE
    

    can any one help me in understating what is wrong here?

    thanks


  • Lifetime Qt Champion

    @ravi2k18 My guess is that something is wrong in one of the two header files you're including in discoveryobj.h


  • Lifetime Qt Champion

    @ravi2k18 Q_OBJECT must be the first line after { in your class!


  • Moderators

    @ravi2k18 said in error: expected constructor, destructor, or type conversion before ‘enum’ while building in linux with make:

    DiscoveryThread();

    you're derving from QThread/QObject make this a proper constructor with base class initialisation


Log in to reply