Errors, bugs, questions - page 2563

 
Andrey Barinov:

?

It has a static modifier in the example, if you remove it, the compiler will give a warning as it should

static can be accessed from any part of your code with the context resolution operator... from any code fragment at all! (I can't remember the scope, I haven't checked it recently, but most likely it will be global, as if it was described at the very top of the code, i.e. it doesn't matter where the static method/field was declared)

 
Igor Makanu:

A statik can be accessed from any part of the code using the context resolution statement... from any part of the code! (I can't remember the scope, I haven't checked it recently, but most likely it will be global, as if it's described at the very top of the code, i.e. it doesn't matter where the static method/field is declared)

How long ago did it become so :)?

All the same rules apply to statics (private, protected, public), they just don't require object creation.

This is an obvious bug.

 
Andrey Barinov:

How long has it been like this :)?

I don't know, I can tell for sure that a couple of months ago@Ilyas admin was explaining statics initialization procedure, and he mentioned that statics methods and statics fields are initialized together with global variables at MQL-program startup... go further and search through his posts

Andrey Barinov:

All the same rules apply to statics (private, protected, public), they just don't require object creation.

This is an obvious bug.

I am not ready to argue and do not want to, but the help text indicates the behavior of static methods

the MQL code is making great steps towards the behavior of C# programs, the situation is similar there, as well as if the programmer decides to use context resolution operator, it means he consciously refuses the help of compiler to identify violations of data integrity in the class, there are classic ways of getting methods and fields without context resolution operator


UPD: I decided to rewrite my MQL library little by little, I'm horrified to notice that I write as I've seen in popular MQL codes names of methods and fields that coincide with names of reserved words....imho this is also a step to avoid help from compiler when "breaking" dependencies.... so-so ))))

 

Igor Makanu:

as if the programmer decides to use context resolution operator, it means he/she consciously refuses the compiler's help to detect data integrity violation in the class, there are classical ways of obtaining methods and fields without context resolution operator

I think you've smoked too much OOP. Give it a rest and then come back with a clear head. The context resolution statement defines visibility but has no effect on access.

 
TheXpert:

I think you've had too much OOP, take a rest and then with a fresh head. the context resolution statement defines visibility but has no effect on access.

Well, it's up to me to decide what to smoke and when to rest ))))

SZY: there are always lots of tricks in any language with access to memory contents. I read the hobbies there in the comments, there are regular fights about python and c++, once again - there are more humane ways of working with fields and methods, if you decided that it's faster, then you should not blame what you get - in all compilers you could always break in where you shouldn't)))

 
Igor Makanu:

I don't know, I can say for sure that a couple of months ago@Ilyas admin was explaining statics initialization procedure and mentioned that static methods and static fields are initialized together with global variables at MQL-program startup... go further and search through his posts

i'm not ready to argue and don't want to, but the help text represents the behavior of static methods

"private - allows access to variables and methods of a class only from methods of that class. "

Where is the word "only" unclear?

OnStart is not a method of class A, according to the example.

 
Aliaksandr Hryshyn:

"private - allows access to variables and methods of a class only from methods of that class. "

Where is the word "only" unclear?

OnStart is not a method of class A, according to the example.

We are not talking about the modifier private, but about the modifier static - make tests and see how static behaves in MQL

 
Igor Makanu:

I don't know, I can say for sure that a couple of months ago@Ilyas admin was explaining statics initialization procedure and mentioned that static methods and static fields are initialized together with global variables at MQL-program startup... go further and search through his posts

i'm not ready to dispute, but the help text indicates the behavior of static methods

And imho, I don't think it's necessary to confirm with arguments - MQL is moving a lot towards the behavior of C# programs, it has a similar situation, as well as if the programmer decides to use context resolution operator, it means he consciously declines the help of compiler to identify violations of data integrity in the class, there are classic ways of getting methods and fields without context resolution operator


UPD: I decided to rewrite my MQL library little by little, I'm horrified to notice that I write as I've seen in popular MQL codes names of methods and fields that coincide with names of reserved words....imho this is also a step to avoid help from compiler when "breaking" dependencies.... so-so ))))

https://pikabu.ru/story/nevozmozhno_tak_nevozmozhno_2129852
 

?

it's a strange situation, everything outside the class has been working for a long time with the staichi. and i'm just making a big fuss about it.... Just for fun, reproduce the code yourself:

int print(int value)
{  Print(value,":",__FUNCTION__); 
 return(value);
}
class A
{
private:
   static int        a1;
protected:
   static int        a2;
public:
   static int        a3;

};
//+------------------------------------------------------------------+
static int A::a1 = print(1);
static int A::a2 = print(2);
static int A::a3 = print(3);

//+------------------------------------------------------------------+
void OnStart()
{}
//+------------------------------------------------------------------+

Do you see an object instance? and it exists in MQL ;)

SZZ: And it exists at the level of help... what's your beef with me?

https://www.mql5.com/ru/docs/basis/oop/staticmembers

Not being able to declare class members statically would result in the need to declare this data at the global program level. This would sever the relationship between the data and its class, and is also inconsistent with the basic OOP paradigm of combining data and methods in a class to handle it. A static member allows class data that is not specific to an individual instance to exist in the scope of the class.

Reason: