String Arrays in a structure

 

I am trying to populate a string array inside a structure but the compiler errors every time (see "string Label")

struct PIVOT_Structure
{
   datetime TimeStart;
   datetime TimeEnd;
   double   PP,S1,S2,S3,R1,R2,R3;   
   double   Line[7];
   string   Label[7] = {"HR-PP","HR-R1","HR-R2","HR-R3","HR-S1","HR-S1","HR-S1"}; 
};

if you place the  line outside of the structure then it works fine.

Is there a reason that you cannot initialize the value of the string array inside the structure? It is a pain because it means manually coding the loading of each string value. (I have many of these to do)

 

If I understood well, you need to have the same value for all your variable of PIVOT_Structure type.

So you have to use a static :

struct PIVOT_Structure
  {
   datetime          TimeStart;
   datetime          TimeEnd;
   double            PP,S1,S2,S3,R1,R2,R3;
   double            Line[7];
   static string     Label[];
  };
string PIVOT_Structure::Label[]={"HR-PP","HR-R1","HR-R2","HR-R3","HR-S1","HR-S1","HR-S1"};

So you have a static and dynamic array :-D.

 
angevoyageur:

If I understood well, you need to have the same value for all your variable of PIVOT_Structure type.

So you have to use a static :

So you have a static and dynamic array :-D.

excellent thanks for that :-D
 

I want to initialize an array in a class. the array is in string type. the compiler error is this:

{ - expression expected - The underlined and bolded line of code

And the code is as below

//+------------------------------------------------------------------+
//|                                              CurrencySymbols.mqh |
//|                                                   Amin Mohammadi |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Amin Mohammadi"
#property link      "http://www.mql5.com"
#property version   "1.00"


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

struct Currencies
{
static string Major[];
};

class CurrencySymbols
  {
  protected:
  Currencies currency;


private:
 
  void SetCurrencyValue();
 void GetCurrencyValue();
 void SetCurrencySymbols();
 void GetCurrencySymbols();
public:


                     CurrencySymbols();
                     
                    ~CurrencySymbols();
                    

  };
  
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
CurrencySymbols::CurrencySymbols()
  { 
  
  currency.Major[8]={"AUD", "CAD", "CHF", "EUR", "GBP", "JPY", "NZD", "USD"}; 
  
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
CurrencySymbols::~CurrencySymbols()
  {
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
// Get currencies symbol
//+------------------------------------------------------------------+
CurrencySymbols::GetCurrencySymbols()
{

} 
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
// Set currencies symbol
//+------------------------------------------------------------------+
CurrencySymbols::SetCurrencySymbols()
{

} 
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
// Get currencies Value
//+------------------------------------------------------------------+
CurrencySymbols::GetCurrencyValue()
{
}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
// Set currencies value
//+------------------------------------------------------------------+
CurrencySymbols::SetCurrencyValue()
{
}                    
//+------------------------------------------------------------------+
 
amin_mohammadi:

I want to initialize an array in a class. the array is in string type. the compiler error is this:

{ - expression expected - The underlined and bolded line of code

And the code is as below

You need to initialize your array outside your class :

string Currencies::Major[]={"AUD", "CAD", "CHF", "EUR", "GBP", "JPY", "NZD", "USD"}; 

Why do you need a structure and a class ?

 
angevoyageur:

You need to initialize your array outside your class :

Why do you need a structure and a class ?

Sorry for delay in response,

I need a public static array to save a double value for each currency. I don't know what is the standard way to do that in class.

When I try to put the definition inside the class I get this error.