Search code examples
classooprecursionnamespacesmql4

How to call a built-in function IsTesting() from a class-method which has the same name IsTesting()?


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?


Solution

  • 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
    }