C++中关于调用操作符的重载operator()与自定义构造函数

C++语言 码拜 8年前 (2016-04-26) 1563次浏览
class ThresholdOp               //阈值函数
{
public:
typedef SrcTT SrcT;
typedef TargetTT TargetT;
ThresholdOp(SrcT thre,TargetT s_val,TargetT l_val):m_thre(thre),m_s_val(s_val),m_l_val(l_val){};
inline void operator()(const SrcT& s_val,TargetT& t_val)
{
if ( s_val > m_thre )
t_val = m_l_val;
else
t_val = m_s_val;
}
private:
SrcT m_thre;
TargetT m_s_val;
TargetT m_l_val;
}
有没有例子能说明一下这个重载()的使用?
解决方案

40

C++ 仿函数
去搜索一下你就明白了

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明C++中关于调用操作符的重载operator()与自定义构造函数
喜欢 (0)
[1034331897@qq.com]
分享 (0)