c – 无法推断出模板参数

c – 无法推断出模板参数,第1张

概述我正在实现的类的一部分看起来像这样: 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 { 我正在实现的类的一部分看起来像这样:

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用来命令它的键.

总结

以上是内存溢出为你收集整理的c – 无法推断模板参数全部内容,希望文章能够帮你解决c – 无法推断出模板参数所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1219856.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-05
下一篇2022-06-05

发表评论

登录后才能评论

评论列表(0条)

    保存