A possible approach might be to embed some interpreter (like Lua, Guile, etc...) in your C++ application. Then your advanced user would code some script in that language and can call whatever routine you have embedded into (i.e. interfaced or glued with) that interpreter.
(alternatively, write your own interpreter, but that is a lot more work)
Another approach might be to use dynamic loading facilities, but these are operating system specific. On Linux (and POSIX) you would use dlopen(3) and dlsym(3). Be aware of name mangling, so use extern "C"
for those C++ functions you want to load at runtime with dlsym
(see C++ dlopen mini howto).
A variant could be to generate (with your C++ code) dynamically some C++ source in a temporary file (perhaps from some user input; you want some intermediate AST), fork
a compilation of that code into a temporary plugin, and dynamically load that with dlopen
, then run it (using raw function pointers obtained with dlsym
)
But (in contrast to Haskell or Scheme or Ocaml) there is no REPL in C++, so you need to make one (using the tricks I considered above) if you want some, and that is a difficult task for a C++ newbie. C++ is practically a programming language which should be compiled (practically with a compiler such as GCC or Clang started by some build automation tool like GNU make or ninja). And C++ is a very complex language, difficult to learn and to compile, so all its compilers are rather slow.
BTW, be sure to learn at least C++11.
Perhaps you want some unit testing. There are tools and libraries to help on that (see this answer, and also that list)
I could do a simple switch that recieves the case from a cin
You should consider more fancy stuff. For example, you could at least have some std::map with std::string-s keys and values of some common std::function type then use lambda expressions to fill it.
You could read the latest Dragon Book; it is helpful to learn parsing, interpreting and compiling techniques from it (and they are more relevant to your wish than what you might imagine).
Read also SICP (freely downloadable introduction to programming, using Scheme); it is not about C++ but will help you to relate Haskell with C++ and will improve your thinking about programming.