Compile error since build 930

 

Since Build 930 some of my code won't compile

The error happens when referencing a static variable of a class inside the class itself.

 

class SingletonClass {
private:
    static SingletonClass* singleton; // err: unresolved static variable 'SingletonClass::singleton'

public:
    SingletonClass* get(void) {
        if (singleton == NULL) {
            singleton = new SingletonClass();
        }
        
        return singleton;
    }
};

 

That's no big deal, I can use a global variable... 

 
lamemind:

Since Build 930 some of my code won't compile

The error happens when referencing a static variable of a class inside the class itself.

 

 

That's no big deal, I can use a global variable... 

The new version of the compiler static data members must now be placed.

class CFoo
  {
   static int     m_x;
  };

int CFoo::m_x=10;         <<--- placing a static member

Place you can:

class SingletonClass {
private:
    static SingletonClass* singleton;

public:
    SingletonClass* get(void) {
        if (singleton == NULL) {
            singleton = new SingletonClass();
        }
        
        return singleton;
    }
};

SingletonClass* SingletonClass::singleton = NULL;
 
Fleder:

В новой версии компилятора статические члены-данные теперь необходимо размещать.

Please post in English only on this forum. Thank you.
 

It worked!

Thank you Fleder