考虑以下代码
DERIVED a;
(a.*p_base)();
p_base是指向类成员函数的指针,但它是多态的。 这意味着
{{1}}
将打印DERIVED :: test_f
我怎样才能获得指向基类test_f的指针来进行非多态调用?
答案 0 :(得分:1)
使用std::mem_fun
:http://en.cppreference.com/w/cpp/utility/functional/mem_fn
示例:
DERIVED a;
f = mem_fun(&BASE::test_f);
f(a); // calls BASE's test_f with a pointer to a as the "this" pointer