I've the following MQL4/5 code:
class MQL4 {
public:
static double Ask() {
MqlTick _tick;
SymbolInfoTick(_Symbol, _tick);
return _tick.ask;
// Overriding Ask variable to become a function call.
#define Ask MQL4::Ask()
}
};
void start() {
double ask = Ask; // line 14
};
However it fails to compile under MQL4 or MQL5 as per errors:
> mql /s /mql5 Test.mqh
MQL4/MQL5 Compiler build 1162 (02 Jul 2015)
Test.mqh : information: Checking 'Test.mqh'
Test.mqh(14,16) : error 320: 'Ask' - too complex, simplify the macro
Test.mqh(14,16) : error 239: '::' - syntax error
Test.mqh(14,16) : error 239: '::' - syntax error
Test.mqh(14,16) : error 239: '::' - syntax error
Test.mqh(14,16) : error 239: '::' - syntax error
Test.mqh(14,16) : error 239: '::' - syntax error
Test.mqh(14,16) : error 239: '::' - syntax error
Test.mqh(14,16) : error 239: '::' - syntax error
Test.mqh(14,16) : error 149: unexpected token
Test.mqh(14,16) : error 149: ')' - unexpected token
Test.mqh(14,16) : error 157: 'MQL4' - expression expected
Test.mqh(14,10) : warning 31: variable 'ask' not used
: information: Result 11 error(s), 1 warning(s)
Same errors with the latest 1498 build.
Basically it's saying that Ask
macro is too complex macro. Although it works fine when I rename Ask()
method to GetAsk()
and update the macro definition,
however
I'd like to understand
if there is any other solution without having to renaming it.
Is there any syntax that I can define a macro substitution which can understand the following macro:
#define Ask MQL4::Ask()
without having to rename it while still keeping it in the static class method?