Create an array of structs

 

I am trying to create an array of structs, everything I find online indicates there shouldn't be a problem with that, but I can't seem to get my code to compile when I try to do this.  Here is what I am trying to do:

// Heiken Ashi Candle Struct
int ha = 20;   // Make this number at least 5 more than the number of candles you plan on analyzing
struct heikenAshi {
   double haClose;
   double haOpen;
   double haHigh;
   double haLow;
}; 

struct heikenAshi haCandles[ha];  // Array of 'ha' Heiken Ashi candles with corresponding properties

 

 Any suggestions as to what I'm doing wrong?

 

I would modify it like that:

 // Heiken Ashi Candle Struct

#define ha 20   // Make this number at least 5 more than the number of candles you plan on analyzing
struct heikenAshi {
   double haClose;
   double haOpen;
   double haHigh;
   double haLow;
   heikenAshi() {
	haClose = 0.0;haOpen = 0.0;haHigh = 0.0;haLow = 0.0;
   }
}; 

heikenAshi haCandles[ha];  // Array of 'ha' Heiken Ashi candles with corresponding properties
 
Ovo:

I would modify it like that:

 // Heiken Ashi Candle Struct

 

 

 

 

Thank you for your help!  If you don't mind, could you explain the purpose of putting the heikenAshi()... member in the struct?  I'm a hardware engineer and know just enough programming to get myself in trouble!
 
jt27:
Thank you for your help!  If you don't mind, could you explain the purpose of putting the heikenAshi()... member in the struct?  I'm a hardware engineer and know just enough programming to get myself in trouble!
It is a constructor (a method which is triggered after the structure allocation), and in this case it sets default values to the struct members. Otherwise the values would be undefined (not initialised).