Define Variadic Arguments in Functions?

 

Can We define functions that like 


Print("Hello","World"," !");


http://www.equestionanswers.com/c/variadic-function.php


Can I define these fuctions in mql4 or mql5?

variadic functions
  • www.equestionanswers.com
C/C++ language supports variable argument function or variadic function. The prototype defines a single defined argument along with undefined number of arguments. Prototype Syntax: Int v_printf(char string, ...); The three dots indicate the functions can take more than one/many arguments. Argument parsing: Arguments are pushed in the stack...
 
Shin Joo Young:

Can We define functions that like 


Print("Hello","World"," !");


http://www.equestionanswers.com/c/variadic-function.php


Can I define these fuctions in mql4 or mql5?

Not supported currently.

You could ask to ServiceDesk if they plan to add it.

 
Shin Joo Young: Can I define these fuctions in mql4 or mql5?

No but you can come close.

  1. If the data types are unique, overloaded function names and/or default arguments
    bool SetBuffer(INDEX i,PRICE& b[], Wingding ac,string lab,PRICE ev=EMPTY_VALUE){
       SetIndexArrow(i,ac);                      return SetBuffer(i, b, lab, ev);  }
    bool SetBuffer(INDEX i,PRICE& b[], Wingding ac,           PRICE ev=EMPTY_VALUE){
       SetIndexArrow(i,ac);                      return SetBuffer(i, b, ev);       }
    
    bool SetBuffer(INDEX i,PRICE& b[], ENUM_DRAW_TYPE dt, ENUM_LINE_STYLE ls,
                                       COUNT wid,  string lab,PRICE ev=EMPTY_VALUE){
       SetIndexStyle(i, dt, ls, wid);            return SetBuffer(i, b, lab, ev);  }
    bool SetBuffer(INDEX i,PRICE& b[], ENUM_DRAW_TYPE dt, ENUM_LINE_STYLE ls=EMPTY,
                                       COUNT wid=EMPTY,       PRICE ev=EMPTY_VALUE){
       SetIndexStyle(i, dt, ls, wid);            return SetBuffer(i, b, ev);       }
    bool SetBuffer(INDEX i,PRICE& b[], ENUM_DRAW_TYPE dt, ENUM_LINE_STYLE ls,
                                                   string lab,PRICE ev=EMPTY_VALUE){
       SetIndexStyle(i, dt, ls);                 return SetBuffer(i, b, lab, ev);  }
    bool SetBuffer(INDEX i,PRICE& b[], ENUM_DRAW_TYPE dt,
                                       COUNT wid,  string lab,PRICE ev=EMPTY_VALUE){
       SetIndexStyle(i, dt, EMPTY, wid);         return SetBuffer(i, b, lab, ev);  }
    
    bool SetBuffer(INDEX i,PRICE& b[],             string lab,PRICE ev=EMPTY_VALUE){
       SetIndexLabel(i, lab);                    return SetBuffer(i, b, ev);       }
    bool SetBuffer(INDEX i,PRICE& b[],                        PRICE ev=EMPTY_VALUE){
       SetIndexEmptyValue(i, ev);                return SetIndexBuffer(i, b)
                                                    && ArraySetAsSeries(b, true);  }
    :
    PRICE       bNL[];
    #define     INDICATOR_LABEL1  StringFormat("CBL%i", BarsBack)
    #define     INDICATOR_BUFFER1 bNL,INDICATOR_LABEL1
    
    PRICE       bNLupE[];
    #property   indicator_type4   DRAW_LINE                  // Bug 1090 must set.
    #property   indicator_color4  Aqua
    #define     EMPTY_VALUE_UP_E  PRICE_MIN
    #define     INDICATOR_BUFFER4 bNLupE,LN_STY_E,NO_DATA,EMPTY_VALUE_UP_E
    :
       if(!SetBuffer(1-1,INDICATOR_BUFFER1) ){
       if(!SetBuffer(4-1,INDICATOR_BUFFER4) ){

  2. With OOP, Method cascading - Wikipedia
    class T{public:
      T* set(string s){ ... return &this; }
      T* set(int    i}{ ... return &this; }
    ...};
    
    T t; t.set("value").set(2);
 
whroeder1:

No but you can come close.

  1. If the data types are unique, overloaded function names and/or default arguments

  2. With OOP, Method cascading - Wikipedia

whroeder nailed it. The easiest way is to use method chaining. 

class String
{
   string m_string;
public:
   String* concat(string str)
   {
      m_string+=str;
      return &this;
   }
   string Str() { return m_string; }
};

void OnStart()
{
   String s;
   s.concat("Hello ").concat("world, ").concat("this is ").concat("an example.");
   Print(s.Str());
}
 
nicholish en:

whroeder nailed it. The easiest way is to use method chaining. 

Too much code for simple functionality. I have a better one, which I'll post here once it's complete. https://www.mql5.com/en/forum/352694#comment_18592787
Reason: