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

 
ALXIMIKS:

I forgot about encapsulation. And it can be deleted. And there are no constant pointers here.) Anyway, singleton is not the best pattern.

But at least there are some nice templates. For classes I would probably only dream of.


 
Scriptong:
We were talking about static class members. Besides, in my example m_a is a private member. And such class members can be accessed only from instances of the class. So, the variable's value cannot be changed anywhere in the code, except on instances of the class. It is a matter of writing safe code which eliminates a lot of possible future bugs.


well, i put public thinking otherwise, removing it will change relative to statics - from within the class - nothing ?!

However,not being able to declare class members statically would result in the need to declare this dataglobally in the program.

The topic was left unanswered.

 
sergeev:

it's the coolness of mql that's being touted.

don't bother with the wording

It seems that you shouldn't bother reading the "valiant documentation" at all. Because everything is wrong. And then some "smart guy" comes out, like a few posts above and starts discussing. And the situation is that I'm very attentive. If I read that it's about a particular type of data, I take it that way. If it is a flaw, I should have acknowledged it.
 
ALXIMIKS:

Someone was yelling about singleton

Are there plans to extend the templates to classes and explicit parameter setting? Otherwise it's blaming me and telling me, that I want too much.

P.S., it would be more correct to declare SomeClassclass insideSingleton (thenyou can createonly one instance ofSomeClass), but it's more obvious, though not correct.


I've seen it all before. I was wondering how to apply it specifically to my structure. Not just to see it copied from some source. I can do that too)

And in general, I understood, on Igor's advice, that this probably won't be useful to me. So I'm not talking about this pattern anymore. And as for the dodgy documentation, which differs from the C++ one, that's obviously true. But, again, there's nothing we can do about it.

We'll have to write at least as much as possible for now. Until an alternative is available.

 

Dear Sir, what was wrong with this post???

ALXIMIKS 03.09.2014 15:34 #
hoz:

If class or structure variables don't lose their values during program execution, then why are they declared as static here ?

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


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

For example, we have aCParserclass, intended for parsing texts, and weneed to countthe total number of words and characters processed.It is enough to declare the requiredclass members as static and initialize them globally.Then all instances of the classwill use common word and character counters when working.

Where ever there is a reference to:

Class or structure variables lose their values at runtime

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

it (the static class member) is created as a single instance and does not depend on the number of created objects of a given class.

 

How do the incomprehensible attacks on the structure and class, and the problems you've made up yourself,

concern the fact that you don't understand the basics of OOP and storage duration, as a composite concept of variable properties in general???

 
ALXIMIKS:

Dear Sir, what was wrong with this post?

If you can't read, that's your problem. Here is a quote of what I was asking. If I misspelled somewhere or wrote something wrong in a hurry, it's because "smart guys" like you blabber on and on. If you know how to read, here's a permanent link to a post specifically for the especially cluelesshttps://www.mql5.com/ru/forum/152923/page6#987432

 
What was wrong in the post ?????????????? I can't read, answer the question if you can read)
 
struct A{
   static struct B{
      int x;
      int y;
   }Single;
};


void OnStart()
{
        A::Single.x = 5;
        Alert(A::Single.x);
}
 

You haven't figured out in two days that static behaves differently in stuct and class?

the structures seem to be taken from c and only a little bit pumped up in terms of inheritance,

As for classes, they are full-fledged.

Because of this, you don't have to reserve space for a static variable in structures

struct A{
   static  int x;
};

but you have to reserve space in classes, otherwise you won't:

class B{
public:
   static  int x;
};
int B::x = 0;
Reason: