kenlistian

厚积薄发. 勤为桨,思为帆

   :: 首页 :: 新随笔 ::  :: 聚合  :: 管理 ::
  73 随笔 :: 4 文章 :: 22 评论 :: 0 Trackbacks

 采用bind1st和bind2nd的意思,就是把参数绑定在第一位还是第二位。
继承于binary_function 类.
描述如下
Class binder1st binds the value to the first argument of the binary function, and binder2nd does the same thing
for the second argument of the function.

如下:例子

struct compare_str :binary_function<ST_DataResult*, char*, bool>
{
public:
    bool operator()(ST_DataResult* pDataRet, char* szTypeCode) const
    {
        return strcmp(pDataRet->sType , szTypeCode) == 0 ? true : false;
       
    }
};


。。。

char szTypeCode[4] = {'\0'};
strcpy(szTypeCode, sTypeCode);
pIt = find_if(m_d_ret_data.begin(), m_d_ret_data.end(),
        bind2nd(compare_str(), szTypeCode));

其中把szTypeCode变量传入到compare_str所定义的第二个参数位置传入。
如果写成bind1nd, 则是把szTypeCode作为第一个参数传入,那么会报错。
因为类型不对。


posted on 2008-07-14 16:56 kenlistian 阅读(819) 评论(0)  编辑 收藏 引用 所属分类: cpp

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理