【问题标题】:How to call a built-in function IsTesting() from a class-method which has the same name IsTesting()?如何从具有相同名称 IsTesting() 的类方法调用内置函数 IsTesting()?
【发布时间】:2016-09-19 16:06:44
【问题描述】:

我有以下代码:

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)。

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

【问题讨论】:

    标签: class oop recursion namespaces mql4


    【解决方案1】:

    前缀 IsTesting()::,告诉编译器使用全局范围。例如:

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

    【讨论】:

      【解决方案2】:

      虽然 ::-namespace-resolution 技巧已经勾勒出一种方法,
      整个问题是
      主要是
      充分地设计/重构代码
      根据当前可用和有效的语言语法规则

      There is a "fully" identical set see remark below
      of functions in the New-MQL4.56789 language
      ,
      所以
      可以保持代码库的清洁和使用,并支持编译时指令(甚至可以使用词法 #define 替换相应的情况),但要保持示例的结构:

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

      备注

      有关稳定语言的详细信息(MQL4 已经存在了大约十年)
      突然
      失去了所有的代码库支持
      并且
      经历了许多语法错误
      很长一段时间
      一次失败的接受新的,尚未成熟的产品(由于经纪人方面的许可问题和 MQL5 的明亮的新语言概念,确实没有人在等待)
      结合只是营销胃口,你猜怎么着发生了,
      一个大满贯炸弹大小的撞击坑出现在全球范围内,这为整个代码库(包括DLL 接口重新设计 -- 可以查看我的其他帖子 related to this rather devastating & painfull experience on this subject

      这不是轻率的咆哮,而是血腥的代价,MQL4 DevTeams 不得不为再次运行相同的代码而付出代价,因为它已经运行了多年。

      出于疑惑——要记住的血腥教训。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-11-27
        • 1970-01-01
        • 2016-09-26
        • 1970-01-01
        • 2015-09-19
        • 2016-03-15
        • 2022-10-06
        • 2020-10-23
        相关资源
        最近更新 更多