且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C ++函数指针(类成员)到非静态成员函数

更新时间:2022-11-23 19:44:47

您想要的行是

   return (f.*f.do_something)(5);

(编译 - 我试过了)

(That compiles -- I've tried it)

* f.do_something 指的是指针本身---f告诉我们从 >。但是我们仍然需要给一个对象,当我们调用该函数时,它将是这个指针。这就是为什么我们需要 f。前缀。

"*f.do_something" refers to the pointer itself --- "f" tells us where to get the do_something value from. But we still need to give an object that will be the this pointer when we call the function. That's why we need the "f." prefix.