Questions on OOP in MQL5 - page 89

 
If the structure has one field, that's fine. If there is more, it is pointless and even silly.
 
Dmitry Fedoseev:
If the structure has one field, that's fine. If there is more, it is pointless and even stupid.

Who would want a single-field structure? How does this "structure" help?

 
Mikhail Dovbakh:

Who would want a single-field structure? How does this "structuring" help?

structure wrapper over an array

MQL can't handle pointers, but it can handle structures without constraints, so you have to wrap an array in a structure

 
Igor Makanu:

structure wrapper over an array

MQL can't handle pointers, but it can handle structures without any limitations, so we have to wrap an array into a structure

Wouldn't it be easier to wrap it in a class? Still, the structure is, first of all, an advantage when working with a static data list. Also, when working with a dynamic structure, it's not convenient to land it later.

 
Alexandr Andreev:

Wouldn't it be easier to wrap it up in a class? A structure is primarily an advantage when working with a static list of data. And when you work with a dynamic structure, it's not convenient to land it.

it's simpler at

And to avoid multiplication of types, I made a class that describes the public section of the structure, using these types partially outside the class,

use them as normal structures, the only thing is more colons, but I won't say it bothers me

 
Mikhail Dovbakh:

Who would want a single-field structure? How does this "structure" help?

That was a... what's-his-name... rhetorical thesis))

However, sometimes it may be useful to put one array into a structure and then use an array from these structures.

 
It works fine. There is just one thing. When the structure is returned from the function, it is not the structure created inside the function that is returned, but a copy of this structure, i.e., an implicit copy constructor is started.
 
Vladimir Simakov:
It works fine. There is just one thing. When the structure is returned from the function, it is not the structure created inside the function, but a copy of this structure, that is, the implicit copy constructor is launched.
There is no unnecessary copying, the structure is created in the stack and the required field is copied from it.
 
Aliaksandr Hryshyn:
There is no unnecessary copying, the structure is created in the stack and the required field is copied from it.
This is if the compiler optimizes it. But otherwise, when calling f(), the following thing will happen. The pointer at the top of the stack is shifted by the size of the structure (the result will be returned here). The function code goes up on the stack. Further, in the process of execution we get to the declaration of the structure. The stack pointer again shifts to its size. It is this structure that is filled with the function. Before the function exits, memory allocated for the structure in the function is copied to the memory allocated for the return.
 
Vladimir Simakov:
This is if the compiler co-optimises. Otherwise, when f() is called, the following will happen. The stack node pointer is shifted to the size of the structure (this is where the result will be returned). The function code goes up on the stack. Further, in the process of execution we get to the declaration of the structure. The stack pointer again shifts to its size. It is this structure that is filled with the function. Before the function exits, the memory allocated for the structure in the function is copied into the memory allocated for the return.
Most likely, it optimizes it.
Reason: