I need to execute code in a class definition in C++. I have a macro to add a method to a function pointer after the definition of the method. It expands to a call to std::map.insert that it needs to execute in the definition (think of how Ruby executes code in class definitions).
The class definition might look something like this after macro expansion:
bindings.insert(pair<char, ReturnType (*)(FirstArgument, SecondArgument)>("theFunction",&theFunction));
Would this execute in the definition?
You need to use a global, its constructor will then execute during program initialization.
See for example these questions and these for how to make sure that
map.insertdoesn’t execute until after the map is constructed.