加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 无法推断出模板参数

发布时间:2020-12-16 10:23:54 所属栏目:百科 来源:网络整理
导读:我正在实现的类的一部分看起来像这样: 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 co
我正在实现的类的一部分看起来像这样:

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;

我无法编译上面的代码

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,_Alloc> &' from 'const Layout::Cord'

有什么建议吗?

解决方法

你的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;
    }

操作符LT;是std :: map用来命令它的键.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读