[SOLVED] problem using static pointers
-
wrote on 27 Sept 2011, 07:59 last edited by
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.
-
wrote on 27 Sept 2011, 08:02 last edited by
@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" );@ -
wrote on 27 Sept 2011, 08:34 last edited by
Ops..what a stupid error! Thanks!
-
wrote on 27 Sept 2011, 10:38 last edited by
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" );@ -
wrote on 27 Sept 2011, 11:28 last edited by
Absolutely right!
5/5