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

 
How do I remove the limit of 8 elements in the number of macro arguments, I am short of 8 elements?
 
Seric29:
How do I remove the limit of 8 elements in the number of macro arguments, I am short of 8 elements?

A macro in a macro should be written.

Why not just write functions?

 

is there a way to remove/delete the const modifier with a macro ? and disable it when needed ?

ZS: there is a code:

class COrder {
private:
//--- const to send order
   const int         c_cmd;
   const double      c_volume;
   double            c_price;
   const int         c_magic;
   const int         c_stoploss;
   const int         c_takeprofit;
}

decided to write in a file fields of a class, and restore from a file through the constructor, but the modifier const will interfere with this

the code is almost finished, in theory i can delete all const, but... But I don't want to lose an opportunity of further modification, and const is very helpful during code modifications

 
Igor Makanu:

is it possible to use a macro to remove/delete the const modifier ? and disable it when needed ?

#define const
 
fxsaber:

Hmm, that simple?!

how do I limit the section of the source code where I want to apply the macro?

 
Igor Makanu:

how do I limit the area of the source code where I want to apply the macro?

#undef const
 
Igor Makanu:

is it possible to use a macro to remove/delete the const modifier ? and disable it when needed ?

ZS: there is a code:

decided to write in file fields of class, and restore from file through constructor, but const modifier will interfere with this

the code is almost finished, in theory i can delete all const, but... But I don't want to lose an opportunity of further modification, and const is very helpful during code modifications

What's the idea? Everywhere c_cmd is a constant and one function is not a constant? If so, it's UB (yes μl won't allow to do so), well there because of read only segments, compiler optimizations ...

 
fxsaber:

Hmm, simple again.

THANK YOU!

Vict:

What's the idea? Is c_cmd a constant everywhere and one function is not a constant? If so, it's UB (yes μl won't allow to do so), well there because of read only segments, compiler optimizations ...

I decided to save all the fields of 2 classes with all settings and current states in them when placing a new order (multi-order TS).


I have decided to use a separate structure with fields by field names of classes to be saved - I will just copy the structure in 2 minutes in the editor))), and it is convenient to save the fields with a single call of FileWriteStruct()

and to restore state I will use this constructor for example:

COrder::COrder(SRecovery &property)
:  c_cmd(property.c_cmd),
   c_volume(property.c_volume),
   c_price(property.c_price),
   c_magic(property.c_magic),
   c_stoploss(property.c_stoploss),
   c_takeprofit(property.c_takeprofit)
{

}

in this constructor call, constant fields can be initialized

restoring of data is only needed to reload the terminal

I haven't done it yet, but I'm 99% sure it will work without problems - I didn't want to introduce a new data type (storage structure) - but it will be easier and I can read the code later....commentary is not ours to write - ))))

 
Igor Makanu:

Hmm, simple again.

THANK YOU!

I decided to save all the fields of 2 classes with all settings and current states in them when placing a new order (multi-order TS).


I have decided to use a separate structure with fields by field names of classes to be saved - I will just copy the structure in 2 minutes in the editor))), and it is convenient to save the fields with a single call of FileWriteStruct()

and to restore state I will use this constructor for example:

when this constructor is called, constant fields can be initialized

restoring of data is only needed to reload the terminal

I haven't done it yet, but I'm 99% sure it will work without problems - I didn't want to introduce a new data type (storage structure) - but it will be easier and I can read the code later....comments are not ours to write - ))))

If you don't want to create a temporary structure for writing, try to write fields to the file one by one and then read them from the constructor in the same way. It's not necessarily faster, but the code will definitely look "uglier".
 
fxsaber:
Wrong. It needs a const_cast counterpart, which it doesn't have.