Inattentive me:) Can you explain why this is needed? Why can't the constructor be used?
Because when writing my own code I came across a situation where my structure is involved in a union. The solution with an empty constructor came immediately to mind but it was a bummer that my code had a union. That's why I was asking this question not for the sake of boring me but for practical use.
Run it, saw the problem. It seems that only structures with public fields are allowed with unions now. Then it would be possible to write struct = {0};
Alexey Kozitsyn: Run it, saw the problem. It seems that only structures with public fields are allowed with unions now. Then it would be possible to write struct = {0};
Maybe I misunderstood you again, but this code works without any warnings:
struct STRUCT
{
//private:int i;
};
// Нужен только для того, чтобы показать необходимость решения без конструктора
union UNION
{
STRUCT Struct; // конструктора не должно бытьint i;
};
// Обходим Warning "possible use of uninitialized variable"template <typename T>
void StructInit( T& ) {}
STRUCT Func()
{
STRUCT Res = {0}; // ок!// StructInit(Res); // с этой строкой Warning не появляется, но это какой-то абсурд!return(Res);
}
voidOnStart()
{
Func();
}
Maybe I misunderstood you again, but this code works without any warnings:
That's right, the public structures are initialized. But union has nothing to do with it.
Interestingly, if a structure with a hidden field is made a public field of a new structure, then the new one will not initialize either, even if all fields are open.
Add a default constructor to the structure.
Forum on trading, automated trading systems and trading strategy testing
Bugs, bugs, questions
fxsaber, 2017.09.06 09:38
Inattentive me:) Can you explain why this is needed? Why can't the constructor be used?
Or is it to show an error of structure initialization with a closed field?
Inattentive me:) Can you explain why this is needed? Why can't the constructor be used?
Because when writing my own code I came across a situation where my structure is involved in a union. The solution with an empty constructor came immediately to mind but it was a bummer that my code had a union. That's why I was asking this question not for the sake of boring me but for practical use.
I had to write this twist to avoid this "bug" (is it a bug or not?).
I haven't seen any other solution yet.
Run it, saw the problem. It seems that only structures with public fields are allowed with unions now. Then it would be possible to write struct = {0};
This is not the case.
This is not the case.
Maybe I misunderstood you again, but this code works without any warnings:
Maybe I misunderstood you again, but this code works without any warnings:
That's right, the public structures are initialized. But union has nothing to do with it.
Interestingly, if a structure with a hidden field is made a public field of a new structure, then the new one will not initialize either, even if all fields are open.
Hi, could you tell me if it's possible to declare an array by specifying the number of elements in it with a variable? If not, how can this be done?
Hi, could you tell me if it's possible to declare an array by specifying the number of elements in it with a variable? If not, how can this be done?
https://www.mql5.com/ru/docs/array/arrayresize
Hi, could you tell me if it's possible to declare an array by specifying the number of elements in it with a variable? If not, how can this be done?
ArrayResize()