首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::mem_fun

Defined in header <functional>

template< class Res, class T > std::mem_fun_t<Res,T> mem_fun( Res (T::*f)() );

(1)

(until C++17)(deprecated since C++11)

template< class Res, class T > std::const_mem_fun_t<Res,T> mem_fun( Res (T::*f)() );

(1)

(until C++17)(deprecated since C++11)

template< class Res, class T, class Arg > std::mem_fun1_t<Res,T,Arg> mem_fun( Res (T::*f)(Arg) );

(2)

(until C++17)(deprecated since C++11)

template< class Res, class T, class Arg > std::const_mem_fun1_t<Res,T,Arg> mem_fun( S (T::*f)(Arg) );

(2)

(until C++17)(deprecated since C++11)

创建成员函数包装对象,从模板参数推断目标类型。包装器对象需要指向类型对象的指针。T作为它的第一个参数operator()...

1%29有效呼叫std::mem_fun_t<S,T>(f)std::const_mem_fun_t<S,T>(f)...

2%29有效呼叫std::mem_fun1_t<S,T>(f)std::const_mem_fun1_t<S,T>(f)...

这个函数和相关的类型在C++11中被取消,在C++17中被删除,以支持更一般的std::mem_fnstd::bind,它们都从成员函数创建可调用适配器兼容的函数对象。

参数

f

-

pointer to a member function to create a wrapper for

返回值

函数对象包装f...

例外

%280%29

注记

之间的区别std::mem_funstd::mem_fun_ref前者产生一个函数包装器,期望一个指向对象的指针,而后者--一个引用。

另见

mem_fun_ref (until C++17)

creates a wrapper from a pointer to member function, callable with a reference to object (function template)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券