Features of the mql5 language, subtleties and tricks - page 227

 
fxsaber #:
Compiler limitation.

This is an obvious defect - I think the compiler should call a medical team on such code already

It is hypothetically possible to imagine parentheses in nested macros in such quantity, but not curly brackets.
 
Please advise whether this is the correct behaviour or not, where the sequence of initialisation of fields of a structure/class object depends on the mutual arrangement of the fields and not on the entries after the constructor?
struct A
{
  int Count;
  
  A() : Count(0) {}
};

struct B : public A
{
  int i, j; // Единственная строка, отличающая от C.

  B() : i(this.Count++), j(this.Count++) {}
};

struct C : public A
{
  int j, i; // Единственная строка, отличающая от B.

  C() : i(this.Count++), j(this.Count++) {}
};

void OnStart()
{
  B b;  
  Print(b.i); // 0
  Print(b.j); // 1

  C c;
  Print(c.i); // 1
  Print(c.j); // 0
}

The expectation was to initialise left-to-right as specified in the constructor.

C() : i(this.Count++), j(this.Count++) {}

But it turned out that the initialisation goes from top to bottom by fields. And the specified sequence of initialisation after the constructor is not important. Is this correct?

 
fxsaber #:
Please advise if this is the correct behaviour or not, where the sequence of initialisation of fields of a structure/class object depends on the mutual arrangement of the fields and not on the entries after the constructor?

The expectation was to initialise left-to-right as specified in the constructor.

But it turned out that the initialisation goes from top to bottom by fields. And the specified sequence of initialisation after the constructor is not important. Is this correct?

Why do Developers write such a detailed help if nobody reads it anyway!? I suggest simplifying the help to one sentence: Ask on the forum - they will help you!

 
A100 #:

Why do Developers write such a detailed help if nobody reads it anyway!? I propose to simplify the help to one sentence: Ask on the forum - they will help you!

When the scheme of finding the answer to a question in the help will be clear, I will resort to forum help less often.

 
fxsaber #:

When I understand the scheme of finding the answer to the question in the help, I will use the forum less often.


In "Data Types" -> "Structures and Classes".

In the initialisation list, members can go in any order, but all class members will be initialised according to the order of their declaration.
 
Sergey Gridnev #:

In "Data Types" -> "Structures and Classes"

In the initialisation list, members can go in any order, but all class members will be initialised according to the order in which they are declared.

Thanks. Unfortunately, it's not always clear where and how to look.

 
fxsaber #:

Thank you. Unfortunately, it's not always clear where and how to look.

Yeah. It is.
 

I found a very unpleasant thing in the indicator work (MT5 and MT4).
Events block the timer work.
There is no such thing in Expert Advisor.
Once again I am convinced that it makes no sense to use indicators where stable timer work is required. This is especially true for responsive interfaces.

Here is an indicator demonstrating this problem, where the timer is set to 20 milliseconds and the time between timer events is displayed if it exceeds 100 milliseconds.

#property indicator_chart_window
//+------------------------------------------------------------------+
int OnInit()
  {
   EventSetMillisecondTimer(20);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
   return(rates_total);
  }
//+------------------------------------------------------------------+
void  OnTimer()
  {
   static uint last_time = GetTickCount();
   uint cur_time = GetTickCount();
   if (cur_time-last_time>100) Print(string(cur_time-last_time)+" ms");
   last_time = cur_time;
  }
//+------------------------------------------------------------------+



 
Added.
template <typename T>
class A
{
public:  
  void f() const { ::Print(typename(T)); }
};

void OnStart()
{
  const A<MqlTick> a;
  
  a.f(); // struct MqlTick
}
 
fxsaber #:
Added.

Those who used to write without using const cannot do it now. Otherwise, there will be an error.

template <typename T>
bool IsMqlTick( const T& ) // Без этого const будет неверно работать.
{
  return(typename(T) == "struct MqlTick");
}

void OnStart()
{
  const MqlTick Value1 = {};
  MqlTick Value2 = {};
  
  Print(IsMqlTick(Value1)); // true
  Print(IsMqlTick(Value2)); // true
}

It seems that the innovation promises serious bugs in previously written codes.