2

I've got the following code:

class Check {
public:

    static bool IsTesting() {
#ifdef __MQL4__
        return IsTesting(); // _______ @fixme: Here the infinite recursion occurs
#else
        return (MQL5InfoInteger(MQL5_TESTER));
#endif
    }
};

void OnStart() {
  Print("Starting...");
  if (Check::IsTesting()) { // _______ a first call to a class-method
    Print("This is a test.");
  }
}

in which I've created class method which I want to call, however the code goes into infinite recursion, because the name of the class-method is the same as a system built-in (global) function (IsTesting()), and instead of calling the former, it calls recursively the latter ( it-self ).

How do I clarify that I want to call the global function, not the local class-method, without changing the method name?

kenorb
  • 155,785
  • 88
  • 678
  • 743

2 Answers2

1

Prefix IsTesting() with ::, which tells the compiler to use global scope. e.g.:

static bool IsTesting() {
#ifdef __MQL4__
    return ::IsTesting(); // @fixme: Here is the loop occuring.
#else
    return (MQL5InfoInteger(MQL5_TESTER));
#endif
}
user3666197
  • 1
  • 6
  • 50
  • 92
Alastair Brown
  • 1,598
  • 8
  • 12
1

While the ::-namespace-resolution trick has sketched a way,
the whole issue is to
principally design / refactor code adequately
to the current available & valid language-syntax rules.

There is a "fully" identical set see remark below
of functions in the New-MQL4.56789 language
,
so
one may keep the code-base clean and use, with a support of compile-time directives ( may even use lexical #define substitutions for the respective case ) but to keep the sample's structure:

class Check {
public:

    static bool IsTesting() {
#ifdef       __MQL5__
       return( MQL5InfoInteger( MQL5_TESTER ) );
#else
       return( MQLInfoInteger(  MQL_TESTER  ) );//_____ one could hardly find
                                                // a better example of MetaQuotes Inc.
                                                // practices on artificially
                                                // injecting features not adopted MQL5
                                                // into a stable MQL4 market
#endif
    }
};

Remark

For details on how a stable language ( the MQL4 has been for about a decade )
suddenly
has lost all the code-base support
and
has experienced many syntax-creeps
for a remarkable amount of time
once a failed acceptance of a new, not yet mature product ( due to broker-side licensing issues & a bright new language concepts of MQL5 that nobody was indeed waiting for )
combined with just a marketing appetite and guess what happened,
a Grand-Slam bomb sized impact crater appeared on a global scale, which introduced an immediate must for a major re/factoring of the whole code-base, incl. DLL-interface redesign -- one may check my other posts related to this rather devastating & painfull experience on this subject

This is not a light-minded rant, it is a bloody cost, that MQL4 DevTeams had to pay for getting the same code just to run again, as it was running for years already.

Out of doubts -- a bloody lesson to remember.

Community
  • 1
  • 1
user3666197
  • 1
  • 6
  • 50
  • 92