Look up table: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11



  • Hi All,
    I want to make a look up table, that is used in two functions in the program. The following gives these warnings. What does this warning mean, and how can I get rid of it?
    Cheers,
    Cedric
    My versions:
    Windows 7 enterprise SP1 64 bit
    Qt Creator 3.6.0 Based on Qt 5.5.1 (MSVC 2013, 32 bit)
    QT5.5, mingw492_32

    C:\somewhere\Qt-tutorials\look-up-table\mainwindow.h:21: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
         };
         ^
    C:\somewhere\Qt-tutorials\look-up-table\mainwindow.h:21: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
    
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    
    namespace Ui {
    class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();
    
        const unsigned short myLut[8]=
        {
            0,      0x3f80, 0x4000, 0x4040, 0x4080, 0x40a0, 0x40c0, 0x40e0,
        };
    
    private:
        Ui::MainWindow *ui;
    };
    
    #endif // MAINWINDOW_H
    

  • Moderators

    @cdwijs said in Look up table: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11:

    const unsigned short myLut[8]=
    {
    0, 0x3f80, 0x4000, 0x4040, 0x4080, 0x40a0, 0x40c0, 0x40e0,
    };

    Here you initialize a non-static class member directly inside the class. This is supported in C++11 standard but not before C++11. You either should move the initialization to the constructor or activate C++11 as suggested in the warning message. Put this in your .pro file:

    CONFIG += c++11
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.