【发布时间】:2012-12-19 10:01:15
【问题描述】:
不确定标题是否突出了我的目标。
我可以在编译时动态调用方法吗? 例如:
int CallMethod(string methodName, string methodArg)
{
Foo foo;
return foo.#methodName(methodArg);
}
CallMethod("getValue", "test"); // This would attempt to call on a Foo instance, method getValue with argument "test" -- foo.getValue("test");
谢谢!
【问题讨论】:
-
不,使用模板或宏。
-
您的函数名称是像您在示例中发布的那样是编译时字符串文字,还是要从文件中读取/用户输入等?
-
@Karthik T : 字符串字面量
-
在这种情况下,@YochaiTimmer's 将非常适合您。
标签: c++ macros sfinae compile-time