A question for OOP experts. - page 36

 
Artyom Trishkin:

In the example

Class Y contains variables with types of classes F and Z.

But if you already have objects of classes F and Z created and used somewhere, you will not be able to access them in object Y. There will be two new objects of classes F and Z in object Y.

To get access to the objects of classes F and Z already created and in use, you need to get references to objects F and Z in class Y - then class Y can operate with those data already stored in F and Z, instead of using the new and pristine F and Z.

But if you immediately create such an object-link, then F and Z in it will give access to classes F and Z, and their filling should be done only through class Y - again, give access to objects F and Z from it, get a pointer to the required object and work with it by the pointer.

It's complicated, though. I will think...
 
Artyom Trishkin:

Or, in the class where you want the data of the other class, you can make a method to get a pointer to the desired class.

class CA{
   protected:
   public:
   void f(){
      Print("A");
   }
};

class CB{
   protected:
   CA * a;
   public:
   void f(CA * arg){
      a=arg;
   }
   void f(){
      Print("B");
   }   
   void f2(){
      a.f();
   }    
};

CA a;
CB b;

void OnStart(){
   b.f(GetPointer(a));
   
   b.f();
   b.f2();
   
}
 
Dmitry Fedoseev:

Well, yes. This is when we know where the object is in the CB a and CB b variables. If they are created with new, then the pointers need to be saved, and retrieved from the saved location.

 
Artyom Trishkin:

Well, yes. That's when we know where the object is - in the CB a and CB b variables. But if they are created via new, the pointers need to be saved, and retrieved from the saved location.

Once the object is created, the pointer is known, pass it to another object.

 
Dmitry Fedoseev:

As soon as the object is created, a pointer will be known to pass it to another object.

But if you want to get a pointer to it not at the moment of creation (user clicked the button - new object created), but in the process of further work with the program.

It seems to me that it is more useful to have a list of all pointers to all objects. In this case you don't have to push the pointers to newly created objects to all other objects from other classes. Also, when you create new classes of new objects, you won't need to rewrite the passing of the object pointer to this new class as well. And when you need to get pointers to previously created objects in a new class, just write down the method of getting the right object by its identifier.

However, everyone is crazy in his own way. I am so :)

 
Hmm, and in Sharp and MQL, pointers are descriptors. And the .NET code is officially open a long time ago. Has anyone here tried to port delegates to MQL yet?
 
Alexey Volchanskiy:
Hmm, and in Sharp and MQL, pointers are descriptors. And the .NET code is officially open a long time ago. Has anyone here tried to port delegates to MQL yet?
15.10 remind me, I'll think about it, it'll probably work.
 
Vladimir Simakov:
15.10 Remind me, I'll think about it, it'll probably work out.

what is 15.10?

 
Alexey Volchanskiy:

what is 15.10?

October 15 maybe?

 
Artyom Trishkin:

October 15 maybe?

That's right, but in the meantime it's a holiday.
Reason: