Late class initialization

 

Hi

coding in mql5


myFile.mqh

class SpreadRatio{
 string symbol;
 public:
  Person(string symbol){
   symbol= symbol;
  }
  ~Person(void);

 // do stuff
};


myFile2.mq5

SpreadRatio spreadRatio;   // compile error - wrong parameter count.  <<<<<<<<<<<<<<<<<

int OnInit(){
 spreadRatio = new SpreadRatio(Symbol());
}


Any idea how to do a late initialization in this case?


Thanks

 

The issue isn't with late initialization . . .


void OnStart()
{
    SpreadRatio *spreadRatio = new SpreadRatio(Symbol());
}

class SpreadRatio
{
    string m_symbol;

public:
    SpreadRatio(const string symbol)
    {
        m_symbol= symbol;
    }
    ~SpreadRatio(void);

    // do stuff
};
 
Anthony Garot:

The issue isn't with late initialization . . .


yes I think so