【发布时间】:2011-03-08 01:12:52
【问题描述】:
有没有一种简单的方法可以转发到具有匹配函数签名的成员函数?
typedef std::tr1::function<int(int,int,int,int)> TheFn;
class C
{
int MemberFn(int,int,int,int) { return 0; }
TheFn getFn() {
//is there a simpler way to write the following line?
return [this](int a,int b,int c,int d){ return this->MemberFn(a,b,c,d); };
}
};
【问题讨论】:
-
也许您可以通过查看 std::mem_fun 的实现方式获得一些见解?
-
我认为你需要澄清你在这里真正想要完成的事情。我不认为你所问的(本身)是可能的,但它足够接近,我怀疑一旦我们知道它是什么,潜在的问题仍然可以解决。
-
在我的应用程序中,我有数百个使用可选设置器和获取器初始化的“智能通信块”。大多数情况下,这些只是转发给在特定对象上具有相同签名的成员函数。我希望有像 MagicBind(this, &MemberFn) 这样的东西。我只是想减少代码噪音。
标签: c++ visual-c++ c++11