Hi. I am trying and failing to create custom comparers for generic collections of objects in MQL5. Can someone please help me work out what I'm doing wrong?
Here is a minimal example of what I've tried.
From my understanding of the MQL5 library and templates, this should work. However, the line I've highlighted generates a compiler error:
I thought my code matches the second case exactly, but obviously I'm wrong.
Any help would be greatly appreciated. Thanks!
So turns out the problem was from inheritance and member visibility. I'm not sure those compiler errors were that informative...
I'll include the fix for the reference of others in case someone also hits against this. The class Cmp needed to inherit with public visibility and then all works as desired.
class Cmp : public IComparer<Integer *> { int Compare(Integer *x, Integer *y) {return x.Value() - y.Value();} };
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi. I am trying and failing to create custom comparers for generic collections of objects in MQL5. Can someone please help me work out what I'm doing wrong?
Here is a minimal example of what I've tried.
From my understanding of the MQL5 library and templates, this should work. However, the line I've highlighted generates a compiler error:
I thought my code matches the second case exactly, but obviously I'm wrong.
Any help would be greatly appreciated. Thanks!