Is it possible to implement a singleton pattern in MQL4. - page 6

 
ALXIMIKS:


You are either obtuse or obtuse, sorry to be blunt, written in black and white:

Noooo... You're the slowpoke!
Why? Because you can't read.

And now I'll quote:

ALXIMIKS:

It says that preserving OOP principles and not creating global variables, we can count the number of some words with a static class member,

it(static class member)is created as a single instance and doesn't depend on how many objects of the class are created.

I need the same thing, only from a structure. Or is it hard to understand? How many times was the question raised about how the structure differs from the class, and how many times was the answer that it is almost nothing. There are not so many differences. At least, at least in C++ it is so. I asked this question once on one forum where there are a lot of professionals. Why there is such a difference here is a question.

I said from the beginning that I needed these variables in a single instance. Or is it hard to read?

hoz:

Let me repeat what I need. There's a structure, the members of which must store their values at runtime, but when any method of any class that uses this structure is accessed, the members can be modified. I understand they need to be static. These members should be in a single instance. The members of this structure will be used by many classes and by the Expert Advisor itself as well.

" smart guy " notice the difference? P.S. HIGHLIGHTED IN RED.
 

Regarding the documentation of class distinction and structure read. Again for the "smart guy"ALXIMIKS here:

Classes have a number of differences from structures:

  • The keyword class is used in the declaration;
  • By default, all class members have the access specifier private, unless otherwise specified. The default access type for structure members is public, unless otherwise specified;
  • class objects always have avirtual function table, even if no virtual functions are declared in the class. Structures cannot have virtual functions;
  • thenew operator can be applied to class objects; this operator cannot be applied to structures;
  • classes can onlyinherit from classes; structures can only inherit from structures.

Is there anything about static?

 

Victor, that's something! :-(

You've already been told how and what to do several times.

Why don't you start to get into it?

 
Why, it's better to spit bile and shout that there are hundreds of idiots driving in the oncoming lane.
 
Reading and hoping for a screenshot of the pattern (?).... for a collection...
 
hoz:

Opens the documentation here and sees that:

If class or structure variables don't lose their values at runtime, why are they declared as static here ?

They are in the public section, you can say that as in structure...

back to your rams.

What do you want?

 
sergeev:

what do you want?



Reading the manus:

Not being able to declare class members statically would result in the need to declare theseat the global programlevel.

We're talking about classes and structures. Judging from what I wrote above, according to the documentation there is a difference between a class and a structure, but clearly it's not about whether you can or cannot use the static modifier.

Отсутствие возможности объявлять статически члены класса привело бы к необходимости объявлять эти данные на глобальном уровне программы.

Is there such a thing? Yes, there is!

Going further:

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, which is not specific to an individual instance, to exist in the scope of the class.

Since a static class member is instance-independent, the reference to it is as follows

class_name::variable

Here's what I need to do. my structure members were instance-independent.

I did this by analogy with classes. You see?

 
hoz:

I need that the my structure members were not dependent on an instance of the structure.


struct A
{
int v;
};

static A a;


?

 

why do something? create one global class object and that's it. (oy-yo-yo-yo - structures, then you will understand something of your own again and attack)

Pros:

1) less text

2) more portability

3) if you suddenly need another object, there are no bans on its creation

4) possibly a large amount of data, but this is a question for the developers.

Cons:

1) I don't like referring to fields via object name, I want it via static, understand me all.

 
sergeev:


struct A
{
int v;
};

static A a;


?

Why isn't this done for classes according to the documentation? Why does it take each member out and initialise it behind the class?
Reason: