"constant expected" compiler error -- but it's a constant!!!

skeptic23
32
skeptic23  

WTF


Anyone know why MQL4 doesn't recognize a constant as a constant?

Or is it telling me "constant" when it means "literal"? 

I don't understand why it doesn't like constants.

Fernando Carreiro
7052
Fernando Carreiro  
skeptic23Anyone know why MQL4 doesn't recognize a constant as a constant? Or is it telling me "constant" when it means "literal"? I don't understand why it doesn't like constants.
You cannot use a "constant variable" for the default value. You have to use a "constant" (aka "literal").
William Roeder
25333
William Roeder  
skeptic23: I don't understand why it doesn't like constants.
  1. It likes constants. You are passing a constant variable. Pass a literal.

  2. Or use the preprocessor.

    #define csConstStr "this is a constant"
    #define ciConstINT 0
    void COMPILES(string sString=csConstStr …
  3. Or internalize it with placeholders.

    const string csConstSTR …;
    const int    ciConstInt …;
    void INTERNALIZED(string sStr="DEFAULT", int iInt=EMPTY){
       if( sString == "DEFAULT") sStr = csConstStr;
       if( iInt    == EMPTY)     iInt = ciConstInt;

skeptic23
32
skeptic23  
William Roeder:
  1. It likes constants. You are passing a constant variable. Pass a literal.

  2. Or use the preprocessor.

  3. Or internalize it with placeholders.


HAHA! Thanks man. Right side =/= left side, thanks for making the connection for me. Forgot all about #define.