错误C2664:'bool Strless :: operator()(const TCHAR *&,const TCHAR *&)const':无法将参数1从'wchar_t * const'转换为'const TCHAR *&'

时间:2011-03-29 16:09:57

标签: c++ visual-studio-2010 stl

我正在努力解决系统中的编译错误,这是代码

struct Strless : public binary_function<TCHAR*, TCHAR*, bool>
{   
public :

    bool operator()(const TCHAR* & _Left, const TCHAR* & _Right) const
    {   
        int iVal = _tcscmp(_Left, _Right);

        return (iVal < 0)? true:false;
    }


}; map<TCHAR *, int, Strless> mymap;

3 个答案:

答案 0 :(得分:2)

你的const在错误的地方。地图正在向您传递TCHAR* const,但您正在使用const TCHAR*&,这是不兼容的。您想要const TCHAR* const&

答案 1 :(得分:1)

与问题无关(已经回答)。但是下面的代码是令人厌恶的:

return (iVal < 0)? true:false;

条件运算符完全是冗余的。以下也适用:

return iVal < 0;

condition ? true : false等代码应始终仅由condition替换。除分配/初始化外,切勿使用布尔文字(truefalse)。

答案 2 :(得分:0)

看起来您正在以非unicode方式编译代码,以便TCHAR正在使用char,但您明确地同时使用wstring或类似代码。您需要确保类型一致(使用字符串类型中的value_type在此处有用)。