Jump to content
  • Advertisement
Sign in to follow this  
Koen VB

Static member gives me headaches

This topic is 4709 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

I'm writing an application wrapper class. This is the piece of my code that causes problems: class CApplication { ... public: static bool Keys[256]; ... }; The array is initialized in the constructor. In the WndProc function, I want to use it to store keyboard data, like this: case WM_KEYDOWN: { CApplication::Keys[wParam] = true; return 0; } The program compiles, but I get a linker error: d:\programming\hypercube\application.o(.text+0xa74):application.cp: undefined reference to `CApplication::Keys' I use Bloodshed DevC++.

Share this post


Link to post
Share on other sites
Advertisement
A comment on the design:

If Keys is a static member, then you shouldn't initialize it in the constructor because it will be re-initialized everytime there is a new instance of the class (even if it is only a temporary).

If you intend for there to only be one instance of the class, then there is no reason to make it static, since there will be no other instances that will share it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!