【发布时间】:2012-01-26 17:16:57
【问题描述】:
我需要一个将代码映射到 C++ 成员函数的表。假设我们有这个类:
class foo
{
bool one() const;
bool two() const;
bool call(char*) const;
};
我想要的是这样的表格:
{
{ “somestring”, one },
{ ”otherstring”, two }
};
如果我有一个foo 对象f,f.call(”somestring”) 会在表中查找“somestring”,调用one() 成员函数,并返回结果。
所有被调用的函数都有相同的原型,即它们是 const,不带参数,返回 bool。
这可能吗?怎么样?
【问题讨论】:
-
这一切都可以手工完成。一个更有趣的问题是自动执行的最佳方法是什么。
标签: c++ arrays data-structures member-function-pointers