【发布时间】:2011-11-21 17:54:17
【问题描述】:
我已经编写了一个函子库(基于http://www.tutok.sk/fastgl/callback.html 上的教程)。
目前,我可以编写如下代码:
class MyClass
{
public:
void Test(int a,int b);
};
MyClass c;
Functor2<void,int,int> f=makeFunctor(c,&MyClass::Test);
...
f(1,2);
我想添加另一个功能,以便我可以将参数与实际函数绑定(向前传递),例如:
Functor0<void> f=makeFunctor(c,&MyClass::Test,3,4);
...
f(); // this will use the default parameters 3,4
我知道 boost 具有该功能,但我不想使用它 - 我想自己编写。
我的问题是如何定义一个函子,我还可以在其中传递要在调用本身中使用的默认参数。我不想使用boost和std++的原因是因为这段代码是跨平台的,将在一些没有boost的平台上使用。
【问题讨论】:
-
您有问题吗?
-
C++11 中的标准库也有同样的功能。您确定不想使用 C++11,或者使用 boost 来练习使用新的标准库功能吗?
标签: c++ templates boost metaprogramming functor