[SOLVED] problem using static pointers



  • Hi all,
    I'm sure I'm missing something really stupid, but I cannot see what. I've got a class that defines the following:

    @
    class MainWindow{
    //....
    public:
    static QString* const SETTINGS_MAIN_ORGANIZATION;
    static QString* const SETTINGS_MAIN_NAME;
    }

    QString* const SETTINGS_MAIN_ORGANIZATION = new QString( "ABC" );
    QString* const SETTINGS_MAIN_NAME = new QString( "DEF" );

    @

    and I access the values stored in the static fields as:

    @
    *MainWindow::SETTINGS_MAIN_NAME
    @

    but compiling the application I got an error:

    @undefined reference to `MainWindow::SETTINGS_MAIN_NAME'@

    What am I doing wrong? My aim is to declare a static const value that must be used as a default value, so if there is a smarter way to do it (without using a #define) please let me know.



  • @class MainWindow{
    //....
    public:
    static QString* const SETTINGS_MAIN_ORGANIZATION;
    static QString* const SETTINGS_MAIN_NAME;
    }

    QString* const MainWindow::SETTINGS_MAIN_ORGANIZATION = new QString( "ABC" );
    QString* const MainWindow::SETTINGS_MAIN_NAME = new QString( "DEF" );@



  • Ops..what a stupid error! Thanks!



  • If the strings are static and const, why use pointers?

    @class MainWindow{
    //....
    public:
    static QString const SETTINGS_MAIN_ORGANIZATION;
    static QString const SETTINGS_MAIN_NAME;
    }

    QString const MainWindow::SETTINGS_MAIN_ORGANIZATION = QString( "ABC" );
    QString const MainWindow::SETTINGS_MAIN_NAME = QString( "DEF" );@



  • Absolutely right!


Log in to reply
 

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