Failure declaring static array

 

Hello,


I want to declare static arrays to be used in different classes, so they should be initialized only once. I also want to directly assign values to the arrays. Putting these arrays into the public part of the class, I get an '=' - illegal assignment use error. Putting them into the Initialize() function, however, works....


class Test
  {
private:

public:

   static double A[]   = {0,     10,    10,    10,    10,    20,   20,   20};
   static double B[]   = {0,     60,    60,    60,    60,    60,   60,   60};

   void              Initialize();
                     Test();
                    ~Test();
  };
//+------------------------------------------------------------------+ 
//|                                                                  |
//+------------------------------------------------------------------+
Test::Initialize()
  {


  }
 
algotrader01:

Hello,


I want to declare static arrays to be used in different classes, so they should be initialized only once. I also want to directly assign values to the arrays. Putting these arrays into the public part of the class, I get an '=' - illegal assignment use error. Putting them into the Initialize() function, however, works....


You need to initialize the static variables on the global scope.

class Test
  {
private:

public:

   static double     A[];
   static double     B[];

   void              Initialize();
                     Test();
                    ~Test();
  };
double Test::A[]   = {0,     10,    10,    10,    10,    20,   20,   20};
double Test::B[]   = {0,     60,    60,    60,    60,    60,   60,   60};
 
Cool, that is doing the job. Haven't seen that before. Thank you Alain!
Reason: