OOP, templates and macros in mql5, subtleties and uses - page 3

 
Алексей Тарабанов:

You have found a way to create it.

You are confused about something.
 
Ilya Malev:

You are trying to use a static fieldof a class at the initialization stage before at least 1 instance of that class has been created. In my opinion, this is a perversion... This is how it works normally:

Encapsulation principle generally implies that such fields should be hidden, not public.

A static field is for this reason that it doesn't depend on having instances of the class. But if you want to create an instance of the class first - ok, create it, but only inside the function. And request this field from it (either directly or through a method) - the result is the same again.

 
Alexey Navoykov:
You are confused about something.

No, I'm not confused about anything.

Global level variables first, then static variables and then local variables as they appear in the code.

This particular example violates the documentation's recommendation not toinitialize variables with functions. It was easier for the developers to write such a warning than explain where they must and must not.

Remove static from your sample and get the result you want.

 
Алексей Тарабанов:

No, I'm not confused about anything.

Global level variables first, then static variables and then local variables as they appear in the code.

This particular example violates the documentation's recommendation not toinitialize variables with functions. It was easier for the developers to write such a warning than explain where they must and must not.

Remove static from your example and get the desired result.

"Documentation's recommendation" )) I'm amazed at you. You really still don't get it, do you? There's a bug in the language. The developers themselves are talking about it, and are explaining to you how to properly tambourine in order not to run into this bug. I made sure to forget about this bug once and for all.
 
Alexey Navoykov:

If it's a constant (and global visibility mostly declares constants, if the code is smart), there's no other choice.

Concerning everything in yellow, I have one question: WHY? I have already figured out how to solve the problem.

HERE so as not to make a mess of what you've already made.

 
Alexey Navoykov:
"Documentation Recommendation" )) I'm amazed at you. Have you really still not grasped the point? There's a bug in the language. The developers themselves are talking about it, and explain you how to properly tambourine in order not to run into this bug. I made sure to forget about this bug once and for all.

You cannot initiate the value of something with a function. Even if you really want to. Don't you get it?

 
Alexey Navoykov:

A static field is a static one, so it does not depend on instances of the class. But if you want to create an instance of the class first, OK, create it, but only inside the function. And request this field from it (either directly or via method) - the result will be the same again.

So, is it procedural or object-oriented programming? Why should we execute functions not related to classes at the stage before initialization with reference to typed objects besides. I understand that the answer is "because I feel like it". But if I were the developer, I would not hurry to cancel everything and run to fix this particular behavior, because it is a rather marginal architecture and besides, the problem is easily solved by creating an instance of the class. Not inside the function, of course.

 
Alexey Viktorov:

FOREVER, so as not to make a mess of the mess you've already made.

I've already done it and I don't regret it one bit) But you, I see, take great pleasure in constraining yourself with artificial restrictions imposed by MQ. Maybe you're a masochist? ) And yet you so insistently try to convince me that this is the way to do it. It's not necessary, it's forced.
 
Алексей Тарабанов:

You cannot initiate the value of something with a function. Even if you really want to. Don't you get it?

Yes, I don't understand. Explain.
 
Ilya Malev:

So is it procedural or object-oriented programming? Why, all of a sudden, to perform functions not related to classes before initialization with respect to typed objects. I understand that the answer is "because I feel like it". But if I were a developer, I would not hurry to cancel everything and run to fix this particular behavior, because it is a rather marginal architecture and besides, the problem is easily solved by creating an instance of the class. Not inside a function, of course.

So you're a supporter of mass use of global variables, as I understand it. Then you and I are unlikely to understand each other.

Moreover, the function itself may be a template. And the created instance, respectively, should be parameterized by the same type:

template<typename T>
int f()
{  
  A<T> a;
  return a.f();
}

What do you do?

Reason: