Features of the mql5 language, subtleties and tricks - page 188
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
The question is how you can start a non-static class method by a pointer even if the object of other class (in this case CTimer) is a property (variable) of the class.
no.... of course you can pass a pointer to another object and change the pointer there to call method.... but you need to know the name of the method.
ZS: but wrote yesterday, use an example@fxsaber and inherit, in each class will be called by OnTimer , there will only be a base class in the loop to check which timer has what timer interval, and the launch of the main timer in static method implement
The question is how you can use a pointer to run a non-static method of a class even if the object of another class (in this case CTimer) is a property (variable) of that class. Is it possible? I'm afraid not.
- templates
- interfaces
templates:
No implementation of the timer itself here, just an example of how to call a non-static function (wrote directly in the forum, didn't check)
Forum on trading, automated trading systems and trading strategy testing
MT5 and Speed in Action
fxsaber, 2020.10.04 11:56
Determines if a program is running on a braked machine or not.
The question is how to run a non-static class method by pointer even if the object of another class (in this case CTimer) is a property (variable) of this class. And is it possible? I'm afraid not.
In general terms, it looks like this:
You can download the lib from here: https://github.com/sva04091979/STD/tree/TimerEvent. TimerEvent branch, not yet merged into the master.
no.... of course you can pass a pointer to another object and change the pointer there to call method.... but you need to know the name of the method.
ZS: but wrote yesterday, use an example@fxsaber and inherit, in each class will be called by OnTimer, it will only remain in the base class in the loop to check which timer has what timer interval, and the launch of the main timer in static method implement
Igor, I don't understand what fxsaber code we're talking about
templates:
There's no implementation of the timer itself, only an example of how to call a non-static function (wrote directly on the forum, didn't check)
Thank you. Tried it. Nothing comes out.
In general, it looks like this:
You download the library from here: https://github.com/sva04091979/STD/tree/TimerEvent. TimerEvent branch, I haven't merged it into the master yet.
Thank you. But I haven't found how to run a non-static class method by the pointer either.
It seems that there is no solution to this problem in the current state of the MQL5 languageThanks to all of you, but maybe I haven't worded the task correctly or haven't found a solution in your article due to my limited knowledge.
What do you need?
Here is an example of an indicator.
The method Timer4 (marked blue) of CTestTimer class is launched by the pointer from CTimer class (in the loop of CTimer:: OnTimer method) passed to CTimer::NewTimer class at the moment of constructor execution when the object of CTestTimer class is created.
I tried everything. There is a deadlock. There is no way to get a pointer to this method. In C++ it works through: typedef void (CTestTimer::*TFun)();
And there is a strange error: 'Timer4' - pointer to this function type is not supported yet ('Timer4' - pointer to this function type is not supported yet)
"For now" - as if MQ put this question aside till better times.
Igor, I do not understand which fxsaber code we are talking about
https://www.mql5.com/ru/forum/325418/page4#comment_16116740
the value of this code is.... well, you can create your own dynamic object anywhere in the code -.... and don't bother updating it, and it will be nailed down by itself when you exit the program
the number of such timers is limited only by your imagination... I wanted to move a sprite - created an object that crawled from the left edge of the screen to the right and killed itself - so to speak, complete autonomy
...too lazy to write an example, not an interesting task
https://www.mql5.com/ru/forum/325418/page4#comment_16116740
the value of this code.... well, you can create your own dynamic object.... anywhere in the code and don't bother updating it and when you exit the program, it will be nailed down by itself
the number of such timers is limited only by your imagination... I wanted to move a sprite - created an object that crawled from the left edge of the screen to the right and killed itself - so to speak, complete autonomy
...too lazy to write an example, not an interesting task
Yeah, I took a quick look at it.
didn't get it
Yeah, I took a quick look at it.
didn't understand that point.
I don't know why the code looks like that now, but it should be:
but you don't need these methods for the timer, imho.
ZS: the object can kill itself like this
I don't know why the code looks like that, but it should be:
but you don't need these methods for the timer, imho.
ZS: The object can kill itself like this
Got it, thanks to you and @fxsaber. Saved it in my piggy bank.
But, of course, there is no answer to my question in this code.