PLO. Application issues

 

The topicof "PLO" has turned into a "good or bad" exchange of opinions. I would like answers to more down to earth questions.

The question is this. In a textbook on C++ I've encountered a mention that an instance of a class can be made the descendant of two different parent classes simultaneously, like

class A
{...}
class B
{...}
class C : public A : public B
{...}

Or something similar (can't find the source). What is the situation in MQL5? Is it possible to declare that the class is a descendant of two different parent classes? What's the syntax?

Isn't the phrase from Help: "No multiple inheritance" about this situation?

 
Yedelkin:

The topicof "PLO" has turned into a "good or bad" exchange of opinions. I would like answers to more down to earth questions.

The question is this. In a textbook on C++ I've encountered a mention that an instance of a class can be made the descendant of two different parent classes simultaneously, like

Or something similar (can't find the source). What is the situation in MQL5? Is it possible to declare that the class is a descendant of two different parent classes? What's the syntax?

Isn't the phrase from Help: "No multiple inheritance" about this situation?

In MQL5 multiple inheritance is not supported, but there is an interesting mechanism for passing of the object pointer, through which something like this can be implemented.

 

With OOP, it's very easy to structure code (pardon the triviality). You take and stamp methods one by one. It's very effective and clear. But a question arises: doesn't this multiple wrappers affect the code processing speed of the processor? Specifically, is there any difference in execution speed between these two code fragments?

double ddd=0.0;                   //первый вариант кода, инициализация без применения функций/методов
 

double ddd;                       //второй вариант кода, инициализация с применением функций/методов
void function(double a) { a=0.0; }
...
function(ddd);

Or at the compilation stage is the code converted from human to machine language so that both these variants do not differ at all in the processing speed for a computer?

 
Urain:

Multiple inheritance is not supported in MQL5 ...

So "multiple inheritance" is the plurality of parents?

 
Yedelkin:
So "multiple inheritance" is plural parenting?

Yes exactly a class can have one parent, cascading can, but two parents and mql5 cannot.

In principle, instead of inheritance, you could call the "type as parent" class in the class itself and access the "type as parent" data via its pointer.

 
Urain:
Yes exactly a class can have one parent, cascading can, but two parents and mql5 cannot.
OK, got it. I didn't think to look up the meaning of the term right away.
 
Yedelkin:

This code is almost no different from multiple inheritance.

class C_A
  {
public:
                     C_A(void){};
                    ~C_A(void){};
   double            a;
  };
//+------------------------------------------------------------------+
class C_B
  {
public:
                     C_B(void){};
                    ~C_B(void){};
   double            b;
  };
//+------------------------------------------------------------------+
class C_C
  {
public:
   C_A              *ua;
   C_B              *ub;
                     C_C(void){ua=new C_A();ub=new C_B();};
                    ~C_C(void){delete ua;delete ub;};
  };
//+------------------------------------------------------------------+
In fact, class C_C has access to C_A and C_B data via appropriate pointers.
 
Urain:

This code is almost no different from multiple inheritance.

In fact, class C_C has access to data of C_A and C_B through corresponding pointers.

Cool! I wouldn't have thought of creating an instance of an external class in the constructor. Thanks for the help!

Addendum. And in this line

C_C(void){ua=new C_A();ub=new C_B();};

The new operator is applied to the C_A() constructor of the C_A class.

From the Reference book, I understood that the operand of the new operator is the class itself, not its constructor. What peculiarities can there be here?

 
By the way, after a while, designers will have parameters working, which will make life a lot easier for developers.
 
Renat:
By the way, after a while designers will have parameters working, which will make life a lot easier for developers.
Yes, I remember that :)
 
Yedelkin:

Cool! I wouldn't have thought of creating an instance of an external class in the constructor. Thanks for the help!

Addendum. And in this line.

The new operator is applied to the C_A() constructor of the C_A class.

From the Reference book, I understood that the operand of the new operator is the class itself, not its constructor. What peculiarities can there be here?

The new operator creates an instance of the class and a constructor is called along with it. It is written in the syntax, so you cannot call it otherwise.

Everything happens automatically in static declaration.

By the way, this will also work and be automatically destroyed

class C_C
  {
public:
   C_A               ua;
   C_B               ub;
                     C_C(void){};
                    ~C_C(void){};
  };
//+------------------------------------------------------------------+
Документация по MQL5: Основы языка / Операторы / Оператор создания объекта new
Документация по MQL5: Основы языка / Операторы / Оператор создания объекта new
  • www.mql5.com
Основы языка / Операторы / Оператор создания объекта new - Документация по MQL5
Reason: