开发者

error C2664: 'bool Strless::operator ()(const TCHAR *&,const TCHAR *&) const' : cannot convert parameter 1 from 'wchar_t *const ' to 'const TCHAR *&'

I am struggling with a compilation error in the system , Here is the code

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

    bool operator()(const TCHAR* & _Left, const TCHAR* & _Right开发者_如何学Go) const
    {   
        int iVal = _tcscmp(_Left, _Right);

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


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


Your const is in the wrong place. The map is passing you a TCHAR* const, but you're taking a const TCHAR*&, which are not compatible. You want to take a const TCHAR* const&.


Unrelated to the problem (which has already been answered). But the following code is an abomination:

return (iVal < 0)? true:false;

The conditional operator is utterly redundant. The following works just as well:

return iVal < 0;

A code such as condition ? true : false should always be replaced by just condition. Never use boolean literals (true, false) except in assignment / initialisation.


It looks like you're compiling your code in non-unicode fashion so that TCHAR is working out to char but you're explicitly using wstring or similar at the same time. You need to make sure that the types agree (using value_type from your string type can be helpful here).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜