Reputation: 1040
I have been stuck a few days now on this issue, and I cannot find an answer to my problem even though google is fuul of replies it seems like this is quite an abstract problematic.
Here is my code in H:
struct DISPLAYLINE_t {
char *text;
bool isWhite;
void set(char *txt, bool iswhite){text = txt; isWhite = iswhite;};
};
struct DISPLAY {
static DISPLAYLINE_t line1,line2,line3,line4;
void clear(){//dostuff};
};
When I try to access from my Main:
DISPLAY::line1.set(string, FALSE);
I get the following error:
error LNK2019: unresolved external symbol "public: static struct DISPLAYLINE_t DISPLAY::line1" (?line1@DISPLAY@@2UDISPLAYLINE_t@@A) referenced in function WinMain
Any ideas?
Upvotes: 0
Views: 204
Reputation: 126522
You have to provide a definition at global namespace scope for your static data members (at least for those that you are odr-using in your code):
DISPLAYLINE_t DISPLAY::line1;
DISPLAYLINE_t DISPLAY::line2;
DISPLAYLINE_t DISPLAY::line3;
DISPLAYLINE_t DISPLAY::line4;
This live example shows how you should fix your program.
Upvotes: 3