Using a member function pointer within a class

前端 未结 5 671
有刺的猬
有刺的猬 2020-12-28 21:21

Given an example class:

class Fred
{
public:
Fred() 
{
    func = &Fred::fa;
}

void run()
{
     int foo, bar;
     *func(foo,bar);
}

double fa(int x,          


        
5条回答
  •  死守一世寂寞
    2020-12-28 22:09

    Non static class member functions have hidden this pointer as an argument.

    I think, the syntax (this->*func)(foo,bar) is the way to make compiler understand that it need to add this to the function.

提交回复
热议问题