Deprecated behavior, hidden method calling will be disabled in a future MQL compiler version - page 5

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
Here is how to do it properly, btw:
Here is how to do it properly, btw:
So my example could also work like this (the method doesn't even have to be virtual):
So my example could also work like this (the method doesn't even have to be virtual):
In this example because the Name is not virtual there is no override and so there is no dynamic runtime resolution, and you just bypass the Name method in the derived. It could as well be omitted at all, it is not called anyway.
It could as well be omitted at all, it is not called anyway.
I'm sorry, but I don't understand what "IT" is.
What can be omitted? What is not called anyway?
I'm sorry, but I don't understand what "IT" is.
What can be omitted? What is not called anyway?
Run it in the debug mode and check if the Name of the base or the derived is called.
Run it in the debug mode and check if the Name of the base or the derived is called.
Thanks, that surprised me.
In that case, of course, it's not a usable solution and it remains to either explicitly call a method from the parent class or to redeclare all overloaded methods in the derived class even though I only want to change the behavior of one of them.
Thanks, that surprised me.
In that case, of course, it's not a usable solution and it remains to either explicitly call a method from the parent class or to redeclare all overloaded methods in the derived class even though I only want to change the behavior of one of them.
As you understood already, the main issue you get here is due to the overloaded functions in the parent class. But even if there was no overload, so only one method you want to change the behaviour, it's still a bad idea to do it using inheritance, it leads to some surprises as you saw.
The best approach is to use composition instead. The annoying part is you will have to write wrapper functions for all the methods you want to access publicly, as MQL doesn't have the "using" keyword/concept, but it remains the best practice.
And I want to place emphasis on what someone else said, you should avoid using MQL "standard" library as much as possible, as it's terrible and very poorly designed.
As you understood already, the main issue you get here is due to the overloaded functions in the parent class. But even if there was no overload, so only one method you want to change the behaviour, it's still a bad idea to do it using inheritance, it leads to some surprises as you saw.
The best approach is to use composition instead. The annoying part is you will have to write wrapper functions for all the methods you want to access publicly, as MQL doesn't have the "using" keyword/concept, but it remains the best practice.
And I want to place emphasis on what someone else said, you should avoid using MQL "standard" library as much as possible, as it's terrible and very poorly designed.
In MQL4, I almost never used the "standard" libraries and I had good reason to do so. Now that I'm switching to MQL5, I'm familiarizing myself with the "standard" libraries for now so I don't reinvent the wheel. But it looks like it will be less time consuming to write all the necessary libraries by myself. I can easily use (copy-paste) some "ideas" from the "standard" ones.
You're right that using composition is more appropriate than using inheritance in most cases. Especially if the parent class is made up of someone else.
The best approach is to use composition instead.
What exactly do you mean by composition? Could you give an example or link to an example, please?