Suppose I have two classes and I want to bind a callback from class A to an instance of class b.
How could I achieve this with std::bind or Boost in MQL 4?
Any help is greatly appreciated, best regards
holger
You cannot do it like you showed. - std::bind is C/C++ and not available in MQL4/5. - You cannot use Boost library, because macros in MQL are more limited than in C/C++
Function pointers in MQL4/5 can only hold pointers to functions which are not members of a class, struct or union. - You need to define a "normal" function and assign it to your f-pointer variable. - Only known way in MQL4/5 up to now.
EDIT:
For what you have shown and are trying to achieve, I suggest using inheritance instead of callback-pointers. - If you could describe more precisely what you are trying to achieve, there might actually be a better way to do it.
You cannot do it like you showed. - std::bind is C/C++ and not available in MQL4/5. - You cannot use Boost library, because macros in MQL are more limited than in C/C++
Function pointers in MQL4/5 can only hold pointers to functions which are not members of a class, struct or union. - You need to define a "normal" function and assign it to your f-pointer variable. - Only known way in MQL4/5 up to now.
EDIT:
For what you have shown and are trying to achieve, I suggest using inheritance instead of callback-pointers. - If you could describe more precisely what you are trying to achieve, there might actually be a better way to do it.
Hello,
thank you very much for the explanation. I would like to try to use MQL more Event-Driven, but the possibilities seem to be very limited.
For example, I would like to have a class that monitors the market watch and informs subscribers via callback when the selected symbols change.
I had also tried an interface-based approach, but since classes in MQL can only implement a single interface (or class), that's also inappropriate in my opinion.
The last thing I could think of was a message broker where class instances could subscribe to specific topics... ?
I'm more from the C# corner and MQL still gives me a lot of headaches :)
Hello,
thank you very much for the explanation. I would like to try to use MQL more Event-Driven, but the possibilities seem to be very limited.
For example, I would like to have a class that monitors the market watch and informs subscribers via callback when the selected symbols change.
I had also tried an interface-based approach, but since classes in MQL can only implement a single interface (or class), that's also inappropriate in my opinion.
The last thing I could think of was a message broker where class instances could subscribe to specific topics... ?
I'm more from the C# corner and MQL still gives me a lot of headaches :)
OK, got it.
I would go as following:
class __base_subscriber; class __registration { protected: __base_subscriber subscribers[]; __registration() {}; const bool broadcast_message(const string filter_detail) { for(int cnt; ) { subscribers[cnt].broadcast_update(filter_detail); } }; const bool register_subscriber(__base_subscriber* p_new) { //... [some array managing implementation] ... subscribers[ptr] = p_new; }; }; class market_watcher : protected __registration { public: market_watcher() { }; void _OnTickUpdate() { // ... [ some condition evaluation] ... const bool result = broadcast_message(_Symbol); }; }; class __base_subscriber { protected: __base_subscriber() { }; virtual void broadcast_update(const string filter_detail) = 0; }; class my_receiving_client : protected __base_subscriber { public: my_receiving_client() { }; virtual void broadcast_update(const string filter_detail) { // ... [ process the new details] ... return; }; };I hope you get the idea.
Hello,
thank you very much for the explanation. I would like to try to use MQL more Event-Driven, but the possibilities seem to be very limited.
For example, I would like to have a class that monitors the market watch and informs subscribers via callback when the selected symbols change.
I had also tried an interface-based approach, but since classes in MQL can only implement a single interface (or class), that's also inappropriate in my opinion.
The last thing I could think of was a message broker where class instances could subscribe to specific topics... ?
I'm more from the C# corner and MQL still gives me a lot of headaches :)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Suppose I have two classes and I want to bind a callback from class A to an instance of class b.
How could I achieve this with std::bind or Boost in MQL 4?
Any help is greatly appreciated, best regards
holger