OOP, templates and macros in mql5, subtleties and uses - page 25

 

fxsaber:

Probably, some compilers will give warnings in such situations.

The specifier refers to a reference, not to the object as a whole, everything is legitimate, why should the compiler swear?

 
TheXpert:

the specifier refers to the reference and not to the object as a whole, everything is legitimate, why should the compiler swear?

Probably, if it were, there would be no scolding here.

void g1( A& ) {}
void g2( const A& ) {}

void OnStart()
{
  const A a;
  
  g1(a); // 'a' - constant variable cannot be passed as reference
  g2(a); // OK
}
 
fxsaber:

Probably, if that were the case, there would be no swearing here.

This is a constant object, so it is logical that a constant object cannot have a non-constant reference

 
TheXpert:

This is a constant object, so it is logical that a non-constant object cannot have a non-constant reference.

How do I refer to a constant object?

 
fxsaber:

How do I make a reference to a constant object?

void g1( A& ) {}
void g1(const A& ){}
void g2( const A& ) {}

void OnStart()
{
  const A a;
  
  g1(a);
  g2(a);
}

Add an overload.

 
Vladimir Simakov:

Overloading to add.

Isn't such an overload on a constant link?

Forum on trading, automated trading systems and strategy testing

OOP, templates and macros in mql5, tips and tricks

TheXpert, 2020.02.26 15:24

The specifier refers to the reference and not to the object as a whole

 
fxsaber:

Isn't such an overload a constant reference?

What do you want to do?

 
fxsaber:

Isn't such an overload not an overload on a constant reference?

If you want the compiler to crash on your first example, it won't work, because everything is legal there: you don't change the object instance by reference, you change the object instance for which the method is called, while the fact that it can be the same object is not the compiler's problem, but the programmer's headache.

For a class, you can do this trick (for structure, you can't):

class A
{
  int i;
public:
  void f( const A &Value )  
  {
    Print(Value.i); // 0
    
    if (&this!=&Value) this.i = Value.i + 1;
    
    Print(Value.i); // 1
  }
};

void OnStart()
{
  A a;
  
  a.f(a);
}
 
Vladimir Simakov:

If you want the compiler to crash on your first example, it won't, because everything is legal there.

It's not about legality, it's about the fact that the const modifier does not guarantee that the object will remain unchanged.

 

Forum on trading, automated trading systems and trading strategies testing

OOP, templates and macros in mql5, tips and tricks

fxsaber, 2020.02.25 22:23

I've never seen this expression return false.
ORDER_TIME_DONE_MSC == DEAL_TIME_MSC

That is why it is difficult to keep statistics on the order execution time based on trading history.

If we can still compare the value ofORDER_TIME_SETUP_MSC for market orders, it is meaningless for pending orders.


Forum on trading, automated trading systems and strategy testing

Libraries: MT4Orders

fxsaber, 2020.02.27 09:40

0 - 348806: 00:01:57.311
1 - 348530: 00:01:39.027
2 - 348494: 00:01:15.259
3 - 348406: 00:01:07.671
4 - 348950: 00:01:04.869
5 - 348960: 00:01:02.888
6 - 348814: 00:01:00.654
7 - 348392: 00:01:00.642
8 - 348508: 00:00:54.515
9 - 348550: 00:00:54.467


Up to two minutes execution on a running account. Share your stats here. The script doesn't use any libraries, it's suitable for Netting/Hedging.