假设我有以下类:
(可能是元生成的)class MyClass
{
public:
myMethod();
...
}
以下内容假定一些前提:
1.) I have the class name from somewhere (let's pretend)
2.) I have the names of the class methods somewhere ( std::map< std::string, std::function> ... perhaps? )
所以...如果我在运行时可能不知道myMethod()
的名称,有没有一种方法可以使用std::string
调用它呢?这是假设我在某个地方存储了类函数的名称。
MyClass example;
std::string funcName{ findMyMethod() };//get std::string name of myMethod
example.someHowRunMyMethodUsing_funcName_();
我知道C++通常不适合于类似内省的情况,但我想解决这个问题。
谢谢!