I have two classes:
class MyClassInfo {
public:
void AddMethod(std::string name, void* pointer); // I don't know what signature should be
}
class MyClass
{
public:
void SetField1(int f1);
int GetFileld1();
private:
int field1;
};
I need to be able to access the methods of MyClass by name (string) during runtime. I don’t want to use any libraries (except boost) and/or compiler functionality (such as rtti) to do that.
I don’t know which signature I should use in AddMethod method, because I don’t know how to transmit the function pointer to the function. This function must be a universal function which allows to add any method. Maybe you know a better variant how to do that without MyClassInfo. Any help will be appreciated.
That is not possible in directly C++. You will have to look at alternatives like creating a map of names to member function pointers. But even that would require consistent method signatures.
Something like
for instance. Your
AddMethodsignature would then look like thisand you would call it like this