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

 
ALXIMIKS:

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 and attack again)

And you can also write "all in one" bypassing classes and structures. Even in procedural. Write however you want, what do you want from me?

Try to teach Straustrup some more. Write him a letter saying that he has made up a lot of unnecessary stuff. Everyone chooses his own, and everyone writes the way he wants. I feel comfortable writing when everything is divided up according to certain tasks. To distribute everything and call it a piece of work. But when these pieces of code turn into a "black box" it is very convenient. Especially when there is not much extra as you put it:

ALXIMIKS:

4) perhaps a big pile of data, but it's a question for the developers.

By the way, developers have nothing to do with it. Not the point.

I'm waiting for my question, though. I wonder why there is such a difference when there isn't one according to the documentation...

 
hoz:
Why isn't this done for classes according to the documentation? Why does it take out and initialize each member per class?

again zorowo. :)

What do you want us to do?

 
_new-rena:
Reading and hoping for a screenshot of the pattern (?).... for a collection...

sorry, there's some "singles" programming going on... gone.
 

the help is kind of cheesy though, because I still don't understand the phrase

Not being able to declare class members statically would require declaring this dataglobally in the program.

who understood it, please explain what was meant by it ?

 
keekkenen:

who understand, tell me what they are trying to say ?

it's to promote the coolness of mql.

don't bother with the wording.

 
keekkenen:

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

who understand, explain what you mean by that?


Instead of:

class CClass
{
   static int m_a;
};

would only have to be used:

int g_a;

And in the first case, m_a is only available in instances of the CClass class, and in the second, from any part of the program.

 
Scriptong:


Instead of:

would have to be used only:

And in the first case, m_a is only available in instances of the CClass class, while in the second, it is available from any part of the program.


I do not see an advantage/difference between

class CClass
{
   static int m_a;
};

Before

class CClass
{
   public:
    int m_a;
};

it's not the wording, but what is meant by it ?!

 
keekkenen:

I don't see an advantage/difference between

The first is the equivalent of a nimespace.
 
keekkenen:


I don't see an advantage/difference between

We were talking about static class members. Besides, in my example m_a is a private member. And such class members are accessible only from class instances. So, the value of the variable 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.
 

Someone was yelling about singleton

class SomeClass{
public:
   int a;
};

class Singleton{
protected:
        static SomeClass* _self;
        Singleton(){}
        virtual ~Singleton(){}   
public:
        static SomeClass* Instance(){
                if(_self == NULL){
                        _self = new SomeClass();
                }
                return _self;
        } 
        static void DeleteInstance(){
                        delete _self;
        }
};
 
SomeClass* Singleton ::_self = NULL;

void OnStart()
{       
        SomeClass* some_ptr = Singleton::Instance();
        Alert(some_ptr.a);                              // Alert(Singleton::Instance().a); // або просто так
        Singleton::DeleteInstance();
}

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 (in this case youcan createonly one instance ofSomeClass), but it's more obvious, though not correct.