I suggest you do not do that. There are infinite number of strings — what will you do with @Chris70 answer if you pass an invalid name? Can't be one with an enum.
enum FBN {A, XYZ}; void function_by_name(FBN function_name) { switch(function_name){ case A: function_a(); return; case XYZ: function_xyz();return; // or break. // etc... } // switch }
@William: I have examples in my own codes where I also did exactly that, i.e. with the switch operator, and at first I thought about suggesting the same.
I admit that in some cases using enumeration elements has some advantages, e.g. if you want to chose a function as a not hard-coded option selected through a user input variable.
The argument with the infinite possible number of strings - although it's formally correct - doesn't hold though as an improvement, because the number of elements in the enumeration also is predefined and finite (adding the "default" case essentially can't change that).
Plus: he specifically asked for a function name as a string variable, not an enumeration element, so you're answering a different question.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I need to call a function by name. I will construct the function name in a string. once the string is constructed i need to call that function. something similar to how iCustom() function uses indicator's name in a string.