Separating class definition and implementation

 
Is it possible to separate class definition and implementation in MetaTrader 4, as in C++ .h and .cpp files?
All MetaTrader examples have class definition and implementation in the same file.
I would like to give header and *.ex4 compiled files, as in C++ I would give header and lib/dllfiles.
 
There are possibilities but mql is not C++. See this article if it helps...
Promote Your Development Projects Using EX5 Libraries
Promote Your Development Projects Using EX5 Libraries
  • www.mql5.com
A sophisticated reader does not need an explanation of the purpose of hiding function and class implementations in libraries. Those of you who are actively searching for new ideas may want to know that the hiding of the implementation details of classes/functions in an .ex5 file will enable you to share your know-how algorithms with other...
 
spiovesan11:
Is it possible to separate class definition and implementation in MetaTrader 4, as in C++ .h and .cpp files?

When I first began programming MQL4, I did my layout in separate .mqh and .ex4 files, trying to mimic C++. It became tricky because MT4 expects files to be within certain folders.

And, as you have noticed, the tendency for the documentation, examples, code base, etc. most code stays in the .mqh file.

So I stopped trying to fight it and switched to MetaTrader's paradigm.

 

EDIT: I just realized you wanted to distribute compiled library classes.... woops. Still going to leave this here...  


It's pretty janky, but possible. Best to create a "project" and then this is how you implement... 


//classes_h.mqh

class Test{
   public: void test_func();
};

#include "classes_src.mqh"
//classes_src.mqh

#include "classes_h.mqh"

void Test::test_func(void){
   Print("test func!!!");
}
#include "classes_h.mqh"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   Test t;
   t.test_func();
   EventSetTimer(60);
   
//---
   return(INIT_SUCCEEDED);
  }

Then modify the .mproj to set compile=true on the src files. 

{
  "platform"    :"mt5",
  "program_type":"expert",
  "copyright"   :"nicholishen",
  "link"        :"www.wwwwwww.com",
  "version"     :"1.00",
  "description" :"SAMPLE",
  "optimize"    :"1",
  "fpzerocheck" :"1",
  "tester_no_cache":"0",
  "tester_everytick_calculate":"0",

  "files":
  [
    {
      "path":".\\Sample.mq5",
      "compile":"true",
      "relative_to_project":"true"
    },
    {
      "path":".\\classes_h.mqh",
      "compile":"false",
      "relative_to_project":"true"
    },
    {
      "path":".\\classes_src.mqh",
      "compile":"true",
      "relative_to_project":"true"
    }
  ]
}

Then your project will look like this. 


proj

Files:
Sample.zip  2 kb
 
nicholish en:

EDIT: I just realized you wanted to distribute compiled library classes.... woops. Still going to leave this here...  


It's pretty janky, but possible. Best to create a "project" and then this is how you implement... 


Then modify the .mproj to set compile=true on the src files. 

Then your project will look like this. 




Thank you. Does header and other filed in folders in the project compile and combine with in an .ex5 file?
Reason: