Experts: MQL5 Programming for Traders – Source Codes from the Book. Part 7 - page 5

 
thelux9 #:

This is exactly what I needed.

Please, make sure you got the latest update, because you quoted not the most recent one published on this thread.

 
Please fix it.
//+------------------------------------------------------------------+
//| Main class to read opt-file and export it to CSVs |
//+------------------------------------------------------------------+
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]; // cannot convert parameter 'TestCacheInput' to 'const TestCacheInputExtended&'
            inputs[i].extend();
         }
      }


//+------------------------------------------------------------------+
//| Input struct with stringified fields |
//+------------------------------------------------------------------+
struct TestCacheInputExtended: public TestCacheInput
{
   using TestCacheInput::operator=;
 
fxsaber #:
Please fix it.


Thank you. I fixed it a bit differently.

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

It's more convenient and logical, because extend() doesn't need to be explicitly called.

NB: the attached file contains other useful edits.

Files:
OptReader.mqh  24 kb
 
Stanislav Korotky #:

Thank you. Fixed it a little differently.

It's more convenient and logical, because extend() doesn't need to be explicitly called.

NB: the attached file contains other useful edits.

Thanks, now it's even more practical.