ishf fady:
Hi
I am very to MQL4 and I am a learner at the moment. I am creating a simple class as shown below. I would to add constructor in my class, so I can use to build object.
I have this simple script, but getting error;
#property strict
void OnStart(){
CurrencyCount currencyCount1 = CurrencyCount("USD",3);
}
//+------------------------------------------------------------------+
class CurrencyCount {
public:
string currency;
int count;
// Class constructor
public:
CurrencyCount(string incurrency, int incount){
this.currency = incurrency;
this.count = incount;
};
};
I am getting error when I try to compile.
Please can someone help.
Thank you.
try below:
#property strict //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class CurrencyCount { public: string currency; int count; public: CurrencyCount(string incurrency, int incount) { this.currency = incurrency; this.count = incount; }; }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnStart() { CurrencyCount CurrencyCount1("USD",3); Print(CurrencyCount1.currency," ",CurrencyCount1.count); //output: //USD 3 } //+------------------------------------------------------------------+
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi
I am very to MQL4 and I am a learner at the moment. I am creating a simple class as shown below. I would to add constructor in my class, so I can use to build object.
I have this simple script, but getting error;
#property strict
void OnStart(){
CurrencyCount currencyCount1 = CurrencyCount("USD",3);
}
//+------------------------------------------------------------------+
class CurrencyCount {
public:
string currency;
int count;
// Class constructor
public:
CurrencyCount(string incurrency, int incount){
this.currency = incurrency;
this.count = incount;
};
};
I am getting error when I try to compile.
Please can someone help.
Thank you.