让我们有以下类:
class Functor{
int even;
int odd;
Functor(int even, int odd){
this->even=even;
this->odd=odd;
}
void operator()(int x){
if (x%2==0) even+=x;
else odd+=x;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
Functor* e= new Functor(0,0);//Now we have pointer to instance of Functor
return 0;
}
问题:
让我们有指向函数foo
和 Functor 实例的指针e
,这样in(*foo)
定义的函数和函数具有相同的签名。如果不明确重写?operator()
Functor
foo
void (*e)(int x)
void (*e)(int x)