无法推断模板参数

Yak*_*kov 3 c++ comparison key map

我正在实现的类的一部分看起来像这样:

    struct Cord
    {
        int x_cord;
        int y_cord;
        Cord(int x = 0,int y = 0):x_cord(x),y_cord(y) {}
        bool operator()(const Cord& cord) const
        {
            if (x_cord == cord.x_cord)
            {
                return y_cord < cord.y_cord;
            }
            return x_cord < cord.x_cord;
        }
    };
class Cell
    {

    };
std::map<Cord,Cell> m_layout;
Run Code Online (Sandbox Code Playgroud)

我无法编译上面的代码

error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'const Layout::Cord'
Run Code Online (Sandbox Code Playgroud)

有什么建议吗?

NPE*_*NPE 8

你的operator()应该是operator<:

    bool operator<(const Cord& cord) const
    {
        if (x_cord == cord.x_cord)
        {
            return y_cord < cord.y_cord;
        }
        return x_cord < cord.x_cord;
    }
Run Code Online (Sandbox Code Playgroud)

operator<就是std::map用命令的按键.