Problem with struct declaration

 

Hello everyone! I'm having a very strange error when a try to use a struct on my codes. the organization of my code is the following:

file1:

#include <file2>

struct example
{
 double a;
 int b;
};

* the struct is declared in this mqh file

* this mqh file uses functions from another file, so "file2"  is in include section

file2:
#include <file2>

struct example;

* file2 uses the struct declared on file1 and the prototipe of the struct is declared in file2

* so I use the struct declared in file1, in file2

When I compile file2, everything is OK, I get no errors or warnings. The problem is when I try to compile file1. It shows the error: undefined struct 'example' cannot be used. But this is very strange, because when I compile file2, it can see the declaration in file1.I tried to declare the struct in file2, but when I do this the metaeditor says that the struct alread exists (I know, but why the error about the declaration?). I also tried to move the struct to file2, but when I do this, file1 cannot see the declaration anymore, even with the include line and the struct prototipe. But the most strange thing is that there are many others structs in the same conditions with everything working!? Can anyone help me?
 

I have edited your improperly formatted code. In the future, please use the CODE button (Alt-S) when inserting code.

Code button in editor

MQL5.community - User Memo
MQL5.community - User Memo
  • www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.
 
Either put the structure definition above the include in file 1.  Or place it in file 2 where it really belongs

When you do things in order compiling file 1  it does not know about the structure art time of including file 2 which references an unknown structure therefore 
 
Fernando Carreiro #:

I have edited your improperly formatted code. In the future, please use the CODE button (Alt-S) when inserting code.

OK. Thank you for that!
 
Paul Anscombe #:
Either put the structure definition above the include in file 1.  Or place it in file 2 where it really belongs

When you do things in order compiling file 1  it does not know about the structure art time of including file 2 which references an unknown structure therefore 
WoW!! It finaly works! Thank you very much!!
 
file2:
#include <file2>
You can't include yourself.
Reason: