如何调用指向成员函数的成员函数指针?我正在学习回调,这只是为了学习目的。我该如何调用 m_ptr 函数?
class Test{
public:
void (Test::*m_ptr)(void) = nullptr;
void foo()
{
std::cout << "Hello foo" << std::endl;
}
};
void (Test::*f_ptr)(void) = nullptr;
int main()
{
Test t;
f_ptr = &Test::foo;
(t.*f_ptr)();
t.m_ptr = &Test::foo;
// t.Test::m_ptr(); //Does not work
// t.m_ptr(); //Does not work
// (t.*m_ptr)(); //Does not work
return 0;
}