指向仿函数的指针

时间:2013-10-11 06:09:31

标签: c++ function functor

我们有以下课程:

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的实例,这样(*foo)operator()Functor定义的函数具有相同的签名。我们如何能够foo指出void (*e)(int x)而没有明确重写void (*e)(int x)的实现?

0 个答案:

没有答案