Type() method of CObject derivatives in Standard library, always return 0 when casting to CObject. - page 3
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
...
Suppose that I have a subclass of CCheckGroup as UiCheckGroup, it has a private member CCheckBox, I have no way to find out the type of controls in the UiCheckGroup.
So I believe the work around would be defining a virtual Type() method for each control type in a future update of standard library.
Update: I have no way to find out the type of controls in the UiCheckGroup, other than cloning the CCheckGroup or dynamic_cast, or ...
CCheckGroup only has check-boxes. Why would you need to iterate them to get an ID when they can only ever be check-boxes?
Update: I have no way to find out the type of controls in the UiCheckGroup, other than cloning the CCheckGroup or dynamic_cast, or ...
Dynamic cast should be the best way, it should not have any influence on performance since the pointer is the only thing that is allocated, maybe some update of virtual methods table. Not significant at all.
Maybe but iterating all types until you find the good one is really not a nice way to code in my opinion. Having some king of Type is a must.
I don't really see a difference. To prove it here is a benchmark, tested on MT4.
Results:
In terms of perceptible GUI performance there is no difference.
I am an advocat of referring the standard library as a starting point. Its not recieved from mount Sinai, its not holy. It will make life much easier, and also to solve this specific problem.
I agree, however, I have been burned in the past by modifying the standard lib because the updater will replace the files with new updated files and all your changes are lost. If you clone the STL into a different directory then you miss the bug fixes that come with updates. It's always best to subclass whenever possible, and there hasn't been a single example ITT of where subclassing wasn't the solution.
I agree, however, I have been burned in the past by modifying the standard lib because the updater will replace the files with new updated files and all your changes are lost. If you clone the STL into a different directory then you miss the bug fixes that come with updates. It's always best to subclass whenever possible, and there hasn't been a single example ITT of where subclassing wasn't the solution.
I don't really see a difference. To prove it here is a benchmark, tested on MT4.
Results:
In terms of perceptible GUI performance there is no difference.
Your test is not correct. On the approach without type, you need to check all (applicable) derived classes, you have only 1, attached an example with 13 which is not much for a real GUI :
2018.10.16 11:53:39.738 283776 EURUSD,M5: iterations(100000), sanity-check(false): Method=dynamic_cast<>, time=1390
2018.10.16 11:53:38.350 283776 EURUSD,M5: iterations(100000), sanity-check(false): Method=obj.Type(), time=610
Anyway if this method is good for you, no problem. I am just saying there are several approaches and each one is free to choose the one he prefers. Often what is best solution for one is worst solution for someone else.
There are 3 solutions proposed in the thread, people have just to pick one that matches their needs and preferences.
Your test is not correct. On the approach without type, you need to check all (applicable) derived classes, you have only 1, attached an example with 13 which is not much in a real GUI :
2018.10.16 11:53:39.738 283776 EURUSD,M5: iterations(100000), sanity-check(false): Method=dynamic_cast<>, time=1390
2018.10.16 11:53:38.350 283776 EURUSD,M5: iterations(100000), sanity-check(false): Method=obj.Type(), time=610
Anyway if this method is good for you, no problem. I am just saying there are several approaches and each one is free to choose the one he prefers. Often what is best solution for one is worst solution for someone else.
There are 3 solutions proposed in the thread, people have just to pick one that matches their needs and preferences.
Doesn't change a thing. Anything below 2ms is completely imperceptible to the human brain, and the difference between the two methods works out to mere microseconds on a full blown GUI. In this case it all comes down to developer preference. For the record, my preference is to use obj.Type() but in a pinch dynamic-casting will do, and there won't be any negative consequences for doing so.