C++ C++;map有时抛出无效运算符<; struct vector\u nodes\u less { 内联布尔运算符()(常量向量2i&a,常量向量2i&b)常量 { 如果(a.x==b.x&&a.y==b.y)返回false; 如果(a.xb.y)返回false; 回报率(a.x

C++ C++;map有时抛出无效运算符<; struct vector\u nodes\u less { 内联布尔运算符()(常量向量2i&a,常量向量2i&b)常量 { 如果(a.x==b.x&&a.y==b.y)返回false; 如果(a.xb.y)返回false; 回报率(a.x,c++,visual-studio-2013,C++,Visual Studio 2013,当我对上述类型执行操作时,它抛出无效运算符,不允许同时包含a

当我对上述类型执行操作时,它抛出无效运算符,不允许同时包含
a
b
,因此,如果运算符对一对元素返回true,则应按相反顺序为它们返回false。现在考虑对(0, 1)和(1, 0)


编写运算符的最简单方法(如果您不关心具体的顺序)是重用成对的
运算符它不允许同时包含
a
b
,因此,如果您的运算符为成对元素返回true,则应按相反的顺序为它们返回false。现在考虑对(0, 1)和(1, 0)


编写运算符的最简单方法(如果您不关心具体顺序)是重用pair的
运算符无效运算符是什么意思?为什么需要这样编写运算符?是否要实现特定顺序?当我运行程序时,它会崩溃-“调试断言失败!”c:\windows\system32\MSCP120D.dll c:\program Files\Microsoft Visual Studio 12.0\VC\include\xtree line 2010表达式:无效运算符除非指定较少的运算符,否则不会编译。它需要它,因为我使用一个对象作为键。你说的无效运算符是什么意思?为什么要这样写运算符?是否要实现特定顺序?当我运行程序时,它会崩溃-“调试断言失败!”c:\windows\system32\MSCP120D.dll c:\program Files\Microsoft Visual Studio 12.0\VC\include\xtree line 2010表达式:无效运算符除非指定较少的运算符,否则不会编译。它需要它因为我用一个物体作为钥匙谢谢先生我你是一个传奇谢谢先生我你是一个传奇
struct vector_nodes_less
{
    inline bool operator()(const Vector2i& a, const Vector2i& b) const
    {
        if (a.x == b.x && a.y == b.y) return false;
        if (a.x < b.x && a.y < b.y) return true;
        if (a.x > b.x && a.y > b.y) return false;       
        return (a.x < b.x || a.y < b.y);
    }
};

typedef std::map <Vector2i, node*, vector_nodes_less> vector_nodes;
return std::tie(a.x, a.y) < std::tie(b.x, b.y);