Download MetaTrader 5

Class A reference Class B and the other way round

To add comments, please log in or register
Having difficulties in understanding the Trading Signals service? Read the article!
Heinz Traub
314
Heinz Traub 2012.08.03 06:39 

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
1206
Ilyas 2012.09.19 10:40  

class B;

class A
  {
   B *m_b;
  };

class B
  {
   A *m_a;
  };

onewithzachy
2271
onewithzachy 2012.09.19 12:55  
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