Search code examples
functiontypesmql4metatrader4mql5

Is there any way to declare a function that can take both an int and a double as it's argument in MQL4?


I have these two functions:

void CheckOneConditionInt( int    &SettingsEditValueInt );
void CheckOneConditionDbl( double &SettingsEditValueDbl );

They do the same stuff, but one is used with int values and another is used with double values. Is there any way to make it one function that can take int/double as an argument? For example:

void CheckOneCondition( void &SettingsEditValue );

PS: The example does not work of course.


Solution

  • The problem is solved by using templates:

    template<typename T>
    void CheckOneCondition( T &SettingsEditValue );
    

    I can then call it passing double or int parameter.