Download MetaTrader 5

Compile error since build 930

To add comments, please log in or register
1000 developers are involved in Freelance service activity. Sign up!
Enrico Ballardini
1714
Enrico Ballardini 2014.05.02 21:51 

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
1027
Artem Temnikov 2014.05.03 12:41  
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
30775
Alain Verleyen 2014.05.03 15:34  
Fleder:

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

Please post in English only on this forum. Thank you.
Enrico Ballardini
1714
Enrico Ballardini 2014.05.05 00:01  

It worked!

Thank you Fleder 

To add comments, please log in or register