Download MetaTrader 5

Compiler bug in MQL5?

To add comments, please log in or register
nicholi shen
1715
nicholi shen  

Before I submit this to Help-desk can someone tell me if this is a legitimate a compiler bug? This only happens on MQL5, not on MQL4.

#include <Strings\String.mqh>
//+------------------------------------------------------------------+
class String1 : public CString 
{
public:
   template<typename T>       
   String1*        operator =  (const T text)       { Assign(string(text)); return &this;  }
   String1*        operator =  (CString &text)      { Assign(text.Str());   return &this;  }
   String1*        Str         (CString &text)      { Assign(text.Str());   return &this;  }
   String1*        Print(void)                      { ::Print(this.Str());  return &this;  }
};
class String2: public String1{};
//+------------------------------------------------------------------+
void OnStart()
{
   String1 str;
   String1 str1 = "Testing class String1.";
   String2 str2 = "Testing identical clone class, String2.";
   
   (str=str2).Print();     //Works fine on MT5 and MT4
   (str=str1).Print();     //! <--- Works on MT4, but fails to compile on MT5! 
   str.Str(str1).Print();  //       |_ Is the same exact method call, but compiles.
}
//+------------------------------------------------------------------+
Alain Verleyen
Moderator
36747
Alain Verleyen  

That's a long time, and I don't know if you reported this or received an answer, but it's actually not a bug.

There is actually an implicit copy operator on mql5 (from build 1640). That's why you got this behaviour.

Thanks to @Amir Yacoby for his contribution to this answer.

To add comments, please log in or register