class - 如何从具有相同名称 IsTesting() 的类方法调用内置函数 IsTesting()?

标签 class oop recursion namespaces mql4

我有以下代码:

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.");
  }
}

其中我创建了我想要调用的类方法,但是代码进入无限递归,因为类方法的名称与系统内置(全局)函数相同(IsTesting() ),并且它不调用前者,而是递归调用后者( it-self )。

如何澄清我想要调用全局函数,而不是本地类方法,而不更改方法名称?

最佳答案

IsTesting() 前面加上 ::,告诉编译器使用全局作用域。例如:

static bool IsTesting() {
#ifdef __MQL4__
    return ::IsTesting(); // @fixme: Here is the loop occuring.
#else
    return (MQL5InfoInteger(MQL5_TESTER));
#endif
}

关于class - 如何从具有相同名称 IsTesting() 的类方法调用内置函数 IsTesting()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37379764/

相关文章:

PHP 数据库类 - 选择函数

c# - 构造函数重载和类参数

c++ - 我在使用 std::stack 从递归函数中检索值时遇到问题

python - 如何将依赖树的输出解析为扁平结构

c++ - 使用 () 创建类的实例

python - 如何在Python中创建与另一个对象具有相同内容的对象?

Python:使用 locals() 进行编程类实例变量初始化

python flask,使用另一个类将 session 保持在范围内

在另一个类中发送的 c# 数组发回零

c - 显示递归的模拟,给定递归算法