Features of the mql5 language, subtleties and tricks - page 215
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
By the way, if you object a static array X x[n]; and X has a k-tor, then all element fields in it will be zeroed first, even private, and only then the k-tor will be called. So there is no violation of the OOP paradigm in zeroing private fields.
But the fact that the constructor did not work is a bug.
By the way, if we create an array static X x[n]; and X has a k-tor, then all element fields in it are zeroed first, even private, and only then the k-tor is called. So there is no violation of the OOP paradigm in zeroing private fields.
That's great. So, it turns out that zeroing comes BEFORE the constructor, and therefore everything is correct. Thank you!
I looked at my research in MQL5, it could be worse, I even pump up the history in the indicator by several TFs:
I can write a lot of things in a for statement ))))
I have never encountered a void-function call in for statement. I have seen other variants quite often.
I forgot to add, if a class has non-trivial fields (objects), then after zero-init the whole object for such fields their default c-tor will be called.
Read:
The effects of value initialization are:
Read about default-initialized:
UB!
The fact that the compiler initializes you with zeros, doesn't mean anything, today it initializes, and tomorrow, after the next update....
Read:
The effects of value initialization are:
Read about default-initialized:
UB!
The fact that the compiler initializes you with zeros, doesn't mean anything, today it initializes, and tomorrow, after the next update....
My post "Forgot to add...." was written as a supplement to the previous post:
Forum on trading, automated trading systems and testing trading strategies
Peculiarities of mql5 language, tips and tricks
mktr8591, 2021.11.18 18:15
@A100
If you remember that mql was spawned from C++, both these examples (their counterparts) work well there because there are no constructors in these classes (i.e. there is an implicit constructor):
Example in C++:
So if there are no const fields in the structure /class, then the logic is correct.
It considered a certain situation - when a class has no user constructors and there is an implicit constructor that is not deleted. In this case point 1 quoted by you is not appropriate.
Point"2) if T is a class type with a default constructor that is neither user-provided nor deleted (that is, it may be a class with an implicitly-defined or defaulted default constructor), the object iszero-initialized and the semantic constraints for default-initialization are checked, and if T has a non-trivial default constructor, the object isdefault-initialized;".
So it all fits together.
Read:
The effects of value initialization are:
Read about default-initialized:
UB!
The fact that the compiler initializes you with zeros, doesn't mean anything, today it initializes, and tomorrow, after the next update....
Oops. misread it. In this case:
2) if Tis a class type with a default constructor that is neither user-provided nor deleted (that is, it may be a class with an implicitly-defined or defaulted default constructor), the object iszero-initializedand the semantic constraints for default-initialization are checked, and if Thas a non-trivial default constructor, the object isdefault-initialized;Great. It turns out that zeroing comes BEFORE the constructor, so everything is correct. Thank you!
I haven't seen a void function call in a for statement. The other variants are quite common.
You can write anything you like in the 3rd parameter of for statement, in fact, for statement can replace if() statement with {.....}
SZZ: I've also seen macros like
You can write anything you like into the 3rd parameter of the for statement, in fact, the for statement can replace the if() statement with {.....}
SZZ: I've also seen macros like
Take away the semicolon, otherwise the whole point is lost)))
Remove the semicolon, otherwise all meaning is lost))))
yeah, right - this example in macros to put ; when calling a macro, I don't use macros much - no practice