Download MetaTrader 5

Compile error since build 930

To add comments, please log in or register
Enrico Ballardini
1714
Enrico Ballardini  

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... 

Artem Temnikov
1034
Artem Temnikov  
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;
Alain Verleyen
Moderator
31478
Alain Verleyen  
Fleder:

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

Please post in English only on this forum. Thank you.
Enrico Ballardini
1714
Enrico Ballardini  

It worked!

Thank you Fleder 

To add comments, please log in or register