我有以下代码:
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/