C++ static
Sekojošais C++ kods ģenerē sekojošas linkera kļūdas. Cik noprotu, init() neredz paša klases statiskos mainīgos. Kāpēc?
Form.obj : error LNK2001: unresolved external symbol "protected: static struct tagWNDCLASSA Form::wndClass" (?wndClass@Form@@1UtagWNDCLASSA@@A)
Form.obj : error LNK2001: unresolved external symbol "protected: static struct HINSTANCE__ * Form::hInst" (?hInst@Form@@1PAUHINSTANCE__@@A)
Form.obj : error LNK2001: unresolved external symbol "protected: static int Form::cmdShow" (?cmdShow@Form@@1HA)
Form.obj : error LNK2001: unresolved external symbol "protected: static char * Form::cmdParam" (?cmdParam@Form@@1PADA)
Form.obj : error LNK2001: unresolved external symbol "protected: static struct HINSTANCE__ * Form::hPrevInst" (?hPrevInst@Form@@1PAUHINSTANCE__@@A)
/* Form.h */
class Form
{
public:
static void init(char* name, HINSTANCE hInst, HINSTANCE hPrevInst, char* cmdParam, int cmdShow);
Form();
virtual ~Form();
void show();
protected:
static LRESULT CALLBACK windowsProcedure(HWND hwnd, uint message, WPARAM wParam, LPARAM lParam);
static WNDCLASS wndClass;
static HINSTANCE hInst;
static HINSTANCE hPrevInst;
static char* cmdParam;
static int cmdShow;
HWND hwnd;
};
/* Form.cpp */
void Form::init(char* name, HINSTANCE hInst, HINSTANCE hPrevInst, char* cmdParam, int cmdShow)
{
Form::hInst = hInst;
Form::hPrevInst = hPrevInst;
Form::cmdParam = cmdParam;
Form::cmdShow = cmdShow;
wndClass.style = 0;
wndClass.lpfnWndProc = windowsProcedure;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hInstance = hInst;
wndClass.hIcon = 0;
wndClass.hCursor = LoadCursor(0, IDC_ARROW);
wndClass.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wndClass.lpszMenuName = 0;
wndClass.lpszClassName = name;
RegisterClass(&wndClass);
}