Access to nonstatic class from static

First I would like to say hi to everyone here.
I am writing a bit bigger application, and I put it in more logical pieces.
Now I have UI (currently just console IO), one non-static class for serial communication, and one static class with system logic (there will be some ohers later).

The system logic class is static so I don't need to make an object, but I can just accessing methods. Now serial one is non static so I can have global variable HANDLE so I can access to the same handle from all methods. The structure is following:
1
2
3
4
5
6
7
8
9
10
class SerialComm2
{
public:	SerialComm2(void);
	virtual ~SerialComm2(void);
	HRESULT SerialWrite(const unsigned char *pszBuf, DWORD dwSize);
	HRESULT SerialOpenAndConfig();
	HRESULT SerialRead();

private:	HANDLE m_hSerialComm;
};


Then:
1
2
3
4
5
6
7
8
9
10
class systemD
{
public:
	systemD::systemD();
	systemD::~systemD();
	HRESULT static systemD::sendData(unsigned char level);
	HRESULT static systemD::InitializeDL30System();
private: 
	static SerialComm2 port;
};


Now in InitializeSystem method I try port.SerialOpenAndConfig(); and I get error:

1>Linking...
1>systemD.obj : error LNK2001: unresolved external symbol "private: static class SerialComm2 systemD::port" (?port@systemD@@0VSerialComm2@@A)
1>SDKSusi2 (x86)\Debug/DSystemCmdEmpty.exe : fatal error LNK1120: 1 unresolved externals


Can someone tell me what am I missing?
Thanks,
Bojan
static members need to be instantiated. It's difficult to explain why.

Put this globally in one and only one cpp file:

 
SerialComm2 systemD::port;
Hi Disch
thank you very much. It works now. :)
Last edited on
Topic archived. No new replies allowed.