我有以下代码:
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 )。
如何澄清我想要调用全局函数,而不是本地类-方法,而不更改方法名称?
发布于 2016-05-22 21:21:44
用IsTesting()
前缀::
,,它告诉编译器使用全局范围。例如:
static bool IsTesting() {
#ifdef __MQL4__
return ::IsTesting(); // @fixme: Here is the loop occuring.
#else
return (MQL5InfoInteger(MQL5_TESTER));
#endif
}
https://stackoverflow.com/questions/37379764
复制相似问题