Questions on OOP in MQL5 - page 57

 
Dmitry Fedoseev:

Where is the access to x from C2?
Again, a nested class is only a matter of class visibility to create an object. An object of the C2 class can only be created inside the C1 class. That's all. That's the only difference from writing a type:
But surely you call something else a nested class? Tell us what.

It's about the following:

Forum on trading, automated trading systems and trading strategy testing

Bugs, bugs, questions

Vladimir Simakov, 2020.05.16 21:11

class Originator
  {
   int               state;
public:
   class Memento;
   Originator() : state(0){}
   Memento*          getMemento()      {return new Memento(&this);}
   void              setState(int s)   {state=s;}
   void              dumpState()       {printf("State: %i", state);}
///////////////////////////////////////////////////////////
   class Memento{
      int            state;
      Originator*    org;
      public:
                     Memento(Originator* mOrg):state(mOrg.state),org(mOrg){}
      void           restoreState() {org.state=state;}
   };
///////////////////////////////////////////////////////////
  };

Why there is no error: cannot access to private member?
ANSWER:BecauseMementois a Nested/Internal class relative toOriginator

 
Sergey Dzyublik:

We are talking about the following:

Where is the access to the fields of the other class?

 
Dmitry Fedoseev:

Where is the access to the fields of the other class?

Are you kidding, the author of the post highlighted it in yellow for the gifted...

 
Sergey Dzyublik:

Are you kidding me, the author of the post specifically highlighted it in yellow for the gifted...

I see. Only I don't think he was yesterday.https://www.mql5.com/ru/forum/85652/page48#comment_16405154 But this comrade is from your club... so it's okay, right?

I'll even take a screenshot as a memento:

123

 
Dmitry Fedoseev:

I see. Only it didn't seem like it yesterday.https://www.mql5.com/ru/forum/85652/page48#comment_16405154 But this mate is from your club... so it's okay, right?

I'll even take a screenshot as a memento:

Are you mentally OK?
You get directed to a specific post with an allocation, you're dumb, but you can't even accept that and refer to an obscure post from a completely different thread, just to somehow justify yourself...
Good luck...

 
Sergey Dzyublik:

Are you mentally OK?
You're being directed to a specific post with an allocation, you're dumb, but you can't even accept it and refer to an obscure post from a completely different topic, just to somehow justify yourself...
Good luck...

I'm referring to the post from the same thread, the post that started this whole discussion. Can't you see which thread this post is from? So the question arises, maybe you have something wrong with your psyche?

And not dumbed down, but baffled by the surprise. But where did you get this post here - that's interesting.

And mind you, the author of that post only found out yesterday that it's possible. He found it out but did not realize it and that is why he wrote meaningless example in this thread later. Where was the expert looking?

 
It is equally interesting to see the code from that wikipedia link that Igor gave ru.wikipedia.org/wiki/keeper_(template_projecting). The first example is for Java. Why do you need a gasket from the Caretaker class there? Just to be clever? In essence, it all comes down to using an additional structure and two methods - something any idiot, who has never even heard of the Great Sacred Design Patterns, will do, but without unnecessary gaskets and without even realizing his belonging to the "great knowledge".
 
A long time ago, I was asked at a job interview what an object was. I answered - a set of methods and was hired right away. Then I was told that other candidates started talking about cats, their paws, dogs and other things that are written in children's programming books
 
Evgeniy Zhdan:
Long time ago, I was asked at an interview what an object is. I answered - a set of methods and I was hired right away. Then I was told that other candidates started telling about cats, their paws, dogs and other things that are written in children's books about programming

Why is your story instructive? Everyone gets a job this way - you have to be in the right place at the right time, that's all... there was a vacancy as a button man, so they hired you )))

or did you have some foreign certificate at that time?)


ZS: Why do you work? are the costs large? - You have an average check for the EA 100-300 thousand rubles, in my opinion should suffice at least a month )))).


UPD: I got the feeling that I was an unwilling participant in a freak show, it's not right (((

 

Let me explain.

In mql5, the nested class as well as in pluses is a friend of the external one (by the way, this is the point I didn't know). But in mql4 it's not implemented, and you have to write crutches there. That is, this code will compile correctly in mql5, but will cause compilation errors in mql4.

class Originator
  {
   int               state;
public:
   class Memento;
   Originator() : state(0){}
   Memento*          getMemento()      {return new Memento(&this);}
   void              setState(int s)   {state=s;}
   void              dumpState()       {printf("State: %i", state);}
///////////////////////////////////////////////////////////
   class Memento{
      int            state;
      Originator*    org;
      public:
                     Memento(Originator* mOrg):state(mOrg.state),org(mOrg){}
      void           restoreState() {org.state=state;}
   };
///////////////////////////////////////////////////////////
  };

Although, of course, they will write to me that it is not C++, but still I will draw an analogy.

I don't remember anything about nested classes in official mql docs, as well as the peculiarities of access to external fields from it. Consequently, all this makes me think of UB. Yes, it works, but laying the groundwork for it, until the relevant information appears in the docs, is kind of at your own risk.

Reason: