I'm trying to create a static struct in C++:
static struct Brushes
{
static HBRUSH white ;
static HBRUSH yellow ;
} ;
But its not working, I'm getting:
Error 4 error LNK2001: unresolved external symbol "public: static struct HBRUSH__ * Brushes::white"
Why?
The idea is to be able to use Brushes::white, Brushes::yellow throughout the program, without having to create an instance of Brushes.
You have to define the static members somewhere, usually in the .cxx file, e.g.:
HBRUSH Brushes::white;
The reason is that the header file doesn't make the definition, it only declares it.
You should remove the first static from the struct Brushes line. Then you will need to define the initial values (and declare their memory) in a .cpp file as following:
HBRUSH Brushes::white(some_init_value);
HBRUSH Brushes::yellow(some_init_value);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With