Function templates fail since build 2190
Hello,
hope this is not a duplicate, but i've noticed, the documentation to mql5 concerning function templates is showing code, that does not compile any more, redering the template functionality more or less useless. (And broke my code)
The documentation shows an exmpel at https://www.mql5.com/en/docs/basis/oop/templates:
with the code comparing ( "opeartor <()" ) a templated datatype, which the compiler now errors out as illegal operation in use.
This concerns up to build 2204.
How to refactor the code to be able to compile this functionality again?
Help would be very appreciated.
Thank you.
Example code:
I am very sorry for bothering. - My mistake.
To solve the issue above, the Object in use needs to have a comparison operator in place, which was missing.
i added following lines to the object ea_dbl, which enables the compiler to successfully generate comparison-code to the object, which then leads to working code again.
virtual bool operator == (const ea_dbl &inVal) const { return(m_dbl == inVal.m_dbl); } virtual bool operator != (const ea_dbl &inVal) const { return(!operator == (inVal)); } virtual bool operator > (const ea_dbl &inVal) const { return(m_dbl > inVal.m_dbl); } virtual bool operator < (const ea_dbl &inVal) const { return(m_dbl < inVal.m_dbl); } virtual bool operator >= (const ea_dbl &inVal) const { return(m_dbl >= inVal.m_dbl); } virtual bool operator <= (const ea_dbl &inVal) const { return(m_dbl <= inVal.m_dbl); }
Thank you everybody, maybe this helps someone else, when working with templates and objects.
Always implement the basic operators to an object.
Greetings.
template <typename T> bool operator>(const T& lhs, const T& rhs){ return rhs < lhs; } template <typename T> bool operator<=(const T& lhs, const T& rhs){ return !(rhs < lhs); } template <typename T> bool operator>=(const T& lhs, const T& rhs){ return !(lhs < rhs); } template <typename T> bool operator!=(const T& lhs, const T& rhs){ return !(lhs == rhs); }The above didn't compile on build 840. Might now.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
hope this is not a duplicate, but i've noticed, the documentation to mql5 concerning function templates is showing code, that does not compile any more, redering the template functionality more or less useless. (And broke my code)
The documentation shows an exmpel at https://www.mql5.com/en/docs/basis/oop/templates:
with the code comparing ( "opeartor <()" ) a templated datatype, which the compiler now errors out as illegal operation in use.
if(max<arr[n]) // <- Fails to compile: '<' - illegal operation use
This concerns up to build 2204.
How to refactor the code to be able to compile this functionality again?
Help would be very appreciated.
Thank you.
Example code: