Jump to content
  • Advertisement


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


static member functions using static member variables

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

This is my scenario:
class CMyClass{
    static int var;
    static int GetVar();

int CMyClass::GetVar(){
    return var;
I get no compiler errors, but the linker complains "Undefined reference to ''CMyClass::var''". I simply dont get it.

Share this post

Link to post
Share on other sites
You''ll need to actually define your variable. At the moment, it is only declared. To define it, somewhere outside of your class, put int CMyClass::var; , or better, give it an initial value like int CMyClass::var = 0; Typically, assuming you have a .cpp file and a .h file, this line will go in the .cpp file. I typically put them at the top, before all the function declarations.

int Agony() { return *((int*)0); }    Mwahaha... >8)

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!