
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
Is it possible to declare a static array in a public class section and initialise it in the constructor? (as below) (or only element by element?)
you can
or maybe you are looking for a static array initialisation after all?
can a static array be declared in the public class section and initialised in the constructor? (as below) (or only element by element?)
It goes something like this:
In general, this poverty of OOP is striking against its brilliance. Why can't we initialize variables and arrays as usual when declaring them? I don't doubt, theorists will now move a lot of theories proving me an idiot, but still...You can initialize a local array and perform ArrayCopy to the appropriate array field:
This was also a thought, it can be placed in global scope outside of any class as well.
It's even easier, but I wanted it to be OOP))
It goes something like this:
In general, this poverty of OOP is striking against the background of its brilliance. Why cannot we initialize variables and arrays as usual when declaring them? I don't doubt, theorists will now move a lot of theories proving that I'm an idiot, but still...I have the exact same thought)) every time I write using OOP.
This was also a thought, it can be placed in the global scope outside of any class.
It's even easier, but I wanted it to be OOP))
you can
or maybe you are looking for static array initialization after all?
interesting option.
is calling a "method with constructor"?
interesting option.
is this a "method with constructor" call?
no
that's how you initialize statics.
you don't have to initialize it, this is how the code will look like:
this is not a method call but the full name of the field of class A::Mass[5];
but if you delete the line, there is a compiler error - statics need to allocate memory before the class instance is created - this is what the yellow line doesno
this is how the initialisation of statics is written
you don't have to initialize it, that's how the code will look like:
thank you, it turns out that this line(static bool A::Mass[5];) cannot be transferred to constructor in any way?
or is this the only way statics are initialised in a case like this?
post above supplemented
yes, statics should be described separately,@fxsaber helped me to understand ithttps://www.mql5.com/ru/forum/325418/page4#comment_16116740
you can initialize static classes in MQL5 too.
i.e. this line(static bool A::Mass[5];) cannot be transferred to the constructor?
No, it's a static class field. You need to allocate memory in advance, not at the time of creation of the class instance
and you will use it further as an usual array
If the question is about initialization in the form of a single string, then Sergei's version is what you are looking for, and you just don't need statics.
post above supplemented
yes, statics should be described separately,@fxsaber helped me to understand ithttps://www.mql5.com/ru/forum/325418/page4#comment_16116740
you can initialize static classes in MQL as well.
Thanks, now I've tried it and realized that it's possible to access an array that way.
To be honest we have OOP, but I haven't seen it in Help. It's a pity it doesn't describe such nuances.
thanks a lot, everyone who responded!