EA: 交易者的MQL5编程(MQL5 Programming for Traders) - 源代码第七部分 - 页 5

 
thelux9 #:

这正是我所需要的。

请确保您获得的是最新更新,因为您引用的不是本主题上发布的最新版本。

 
请修好它。
//+------------------------------------------------------------------+
// 读取选项文件并将其导出为 CSV 的主类
//+------------------------------------------------------------------+
class OptReader
{
   TesterOptCacheHeader header;
   TestCacheInputExtended inputs[];
   uchar bufferOfInputs[];
   int shapshot[];
   AutoPtr<RecordBase> records;
   
   bool read(const int handle)
   {
      SAFE(FileReadStruct(handle, header));
      if(header.parameters_total)
      {
         TestCacheInput temp[];
         SAFE(FileReadArray(handle, temp, 0, header.parameters_total));
         const int n = ArrayResize(inputs, header.parameters_total);
         for(int i = 0; i < n; ++i)
         {
            inputs[i] = temp[i]; // 无法将参数 "TestCacheInput "转换为 "const TestCacheInputExtended&
            inputs[i].extend();
         }
      }


//+------------------------------------------------------------------+
//| 包含字符串化字段的输入结构
//+------------------------------------------------------------------+
struct TestCacheInputExtended: public TestCacheInput
{
   using TestCacheInput::operator=;
 
fxsaber #:
请修好它。


谢谢。我的修正方法有点不同。

struct TestCacheInputExtended: public TestCacheInput
{
   ...   
   void operator=(const TestCacheInput &other)
   {
      TestCacheInput::operator=(other);
      extend();
   }
};

这样更方便、更合理,因为extend() 不需要明确调用。

注:附件中还包含其他有用的修改。

附加的文件:
OptReader.mqh  24 kb
 
Stanislav Korotky #:

谢谢。改得有点不一样了。

这样更方便、更合理,因为extend() 不需要明确调用。

注:附件中还包含其他有用的修改。

谢谢,现在更实用了。