- www.mql5.com
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.
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?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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.