Using a member function pointer within a class

前端 未结 5 655
有刺的猬
有刺的猬 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-28 21:53

    You need the following funky syntax to call member functions through a pointer:

    (this->*func)(foo, bar);
    

提交回复
热议问题