采用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作為第一個參數傳入,那么會報錯。
因為類型不對。