Download MetaTrader 5

Class A reference Class B and the other way round

To add comments, please log in or register
Heinz Traub
314
Heinz Traub  

Hello,

I don't know how to make a forward reference between two classes (contained in two different files):

[file A.mqh]

#include "B.mqh"

class A
{
    B* myclassB;
};

[file B.mqh]

#include "A.mqh"

class B
{
    A* myclassA;
};

Clearly this won't compile as the declaration "myclassA" is defined as having no type. Even explicitly including file A.mqh has no efect. Putting both classes in one file is ovbiously the same.

How can i make possible this kind of recursion in MQL5?

Thank you guys.

[EDIT]: I believe this one should go in the GENERAL DISCUSSION, sorry, i read this topic after posting: https://www.mql5.com/en/forum/6775

New Forum Category: Trading Systems
New Forum Category: Trading Systems
  • www.mql5.com
New Forum Category: Trading Systems.
Ilyas
1213
Ilyas  

class B;

class A
  {
   B *m_b;
  };

class B
  {
   A *m_a;
  };

onewithzachy
2269
onewithzachy  
TripleHeinz:

Hello,

I don't know how to make a forward reference between two classes (contained in two different files):

[file A.mqh]

[file B.mqh]

Clearly this won't compile as the declaration "myclassA" is defined as having no type. Even explicitly including file A.mqh has no efect. Putting both classes in one file is ovbiously the same.

How can i make possible this kind of recursion in MQL5?

Thank you guys.

[EDIT]: I believe this one should go in the GENERAL DISCUSSION, sorry, i read this topic after posting: https://www.mql5.com/en/forum/6775

Hi TripleHeinz

Include : https://www.mql5.com/en/docs/basis/preprosessor/include says "The preprocessor replaces the line #include <file_name> with the content of the (include) file ... ".

 

 

Documentation on MQL5: Language Basics / Preprocessor / Including Files (#include)
Documentation on MQL5: Language Basics / Preprocessor / Including Files (#include)
  • www.mql5.com
Language Basics / Preprocessor / Including Files (#include) - Documentation on MQL5
To add comments, please log in or register