[英]how could the object passed to C++ STL mem_fun_t call the function whose name is defined inside mem_fun_t
This the code from GNU STL:这是来自 GNU STL 的代码:
template<typename _Ret, typename _Tp>
class mem_fun_t : public unary_function<_Tp*, _Ret>
{
public:
explicit
mem_fun_t(_Ret (_Tp::*__pf)())
: _M_f(__pf) { }
_Ret
operator()(_Tp* __p) const
{ return (__p->*_M_f)(); }
private:
_Ret (_Tp::*_M_f)();
};
Although __p
has a member function that has the same type with _M_f
,how could __p
call _M_f
, __p
don't have a member named _M_f
.虽然
__p
有有同类型的成员函数_M_f
,怎么可能__p
调用_M_f
, __p
没有命名的成员_M_f
。
_M_f
is a pointer to member function, of type _Ret(_Tp::*)()
. _M_f
是指向成员函数的指针,类型为_Ret(_Tp::*)()
。
It is called through the pointer: __p->*_M_f)()
.它通过指针调用:
__p->*_M_f)()
。 The dereference operator *
is very significant there.取消引用运算符
*
在那里非常重要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.