New build produces errors

 

- there is a new reserved word "override"

- its no more possible to convert a string to boolean

 
Doerk Hilger:

- there is a new reserved word "override"

Since build 1430 :

8. MQL5: Added support for 'final' and 'override' modifiers for classes, structures and functions.

'override' modifier for functions
The 'override' modifier means that a declared function should always override the parent class method. Using the modifiers allows you to avoid errors when overriding, such as accidental change of a method signature. For example, the 'func' method accepting the 'int' type variable is defined in the base class:
class CFoo
  {
   void virtual func(int x) const { }
  };
The method is overridden in the inherited class:
class CBar : public CFoo
  {
   void func(short x) { }
  };
But the argument type is mistakenly changed from 'int' to 'short'. In fact, the method overload instead of overriding is performed in that case. While acting according to the overloaded function definition algorithm, the compiler may in some cases select a method defined in the base class instead of an overridden one.

In order to avoid such errors, the 'override' modifier should be explicitly added to the overridden method.
class CBar : public CFoo
  {
   void func(short x) override { }
  };
If the method signature is changed during the overriding process, the compiler cannot find the method with the same signature in the parent class issuing the compilation error:
'CBar::func' method is declared with 'override' specifier but does not override any base class method

- its no more possible to convert a string to boolean

Since build 1495 :

  1. MQL5: Disabled the support for casting of string type to bool. To check strings, one needs to use explicit conditions. For example, in the new build, compilation of the following code will result in an error:
    string str;
    ...
    if(str)                        // will result in "Cannot convert type 'string' to 'bool'" compilation error (no error would appear in the previous versions)
       Print("str is true");
    One should use an explicit condition:
    string str;
    ...
    
    //--- check if the string is initialized
    if(str!=NULL)
       Print("str is true");
    
    or
    
    //--- check if the string value is "true"
    if(StringCompare(str,"true",false))
       Print("str is true");
    
    or
    
    //--- check if the string is integer and is not equal to zero
    if((int)str!=0)
       Print("str is true");
 
Thx Alain. These errors were just reported by some users who use my API.
 
Is there some more I should know?
 
Doerk Hilger:
Is there some more I should know?
Who knows ? Maybe you want me to make a summary
 

Ok, finally I migrated from Build 925 to 1031 now. Everything else seems to work fine ;)

But the string-to-boolean is weird, since boolean-to-string still works. 

For those who bother with the same problem, I created two macros to avoid this at all:

#define STR_TO_BOOL(source) (source=="true" || (int)source!=0)
#define BOOL_TO_STR(value) ((string)(int)value)