• Advertisement

Archived

This topic is now archived and is closed to further replies.

Static protected member variables?

This topic is 5713 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How do I declare static protected member functions? Example:
class CMsgHndlr
{
private:
	CMsgHndlr() {}
	virtual ~CMsgHndlr() {}
	static CMsgHndlr m_MsgHndlr;

public:
	static CMsgHndlr* GetMsgHndlr();	
};

int CMsgHndlr::m_MsgHndlr; // declaration, gives an error.
 
If I compile this code the compiler tells me that it cannot acces the protected member variable m_MsgHndlr and points me to the line "int CMsgHndlr::m_MsgHndlr". But if I delete this line and recompile, I get an unresolved symbol ofcourse. So how do I declare a static protected member variable??? Thanks René

Share this post


Link to post
Share on other sites
Advertisement
Okay, that was a typo. The line "int CMsgHndlr::m_MsgHndlr" is supposed to be "CMsgHndlr CMsgHndlr::m_MsgHndlr". But it still gives me the same error when I compile it. Can someone tell me what im doing wrong?

René

Share this post


Link to post
Share on other sites
OK. In that case, looks like you are running into problems with MS''s compiler, as the code is perfectly legal with that amendment. The problem is with the dtor visibility, not the static member, so a workaround is to make the dtor public.

Share this post


Link to post
Share on other sites

  • Advertisement