Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 比较两个用户定义的类型向量_C++ - Fatal编程技术网

C++ 比较两个用户定义的类型向量

C++ 比较两个用户定义的类型向量,c++,C++,我尝试使用!=,比较两个向量,但VS2015显示了这些错误 Error C2672 'operator __surrogate_func': no matching overloaded function found Error C2893 Failed to specialize function template 'unknown-type std::equal_to<void>::operator ()(_Ty1 &&,_Ty2 &&

我尝试使用!=,比较两个向量,但VS2015显示了这些错误

Error   C2672   'operator __surrogate_func': no matching overloaded function found  
Error   C2893   Failed to specialize function template 'unknown-type std::equal_to<void>::operator ()(_Ty1 &&,_Ty2 &&) const'
错误C2672'运算符_代理项_func':未找到匹配的重载函数
错误C2893未能专门化函数模板“未知类型std::equal_to::operator()(_Ty1&,_Ty2&&)const”
代码:

#包括
结构像素
{
国际货币基金组织;
国际货币基金组织;
像素(整数x,整数y)
{
m_nX=x;
m_nY=y;
}
};
int main()
{
std::载体vtrPixels1;
vtrPixels1.向后放置(1,2);
vtrPixels1.向后放置(3,4);
std::载体vtrPixels2;
vtrPixels2.向后放置(2,2);
vtrPixels2.向后放置(3,4);
if(vtrPixels1!=vtrPixels2)
vtrPixels1=vtrPixels2;
返回0;
}

对于类
像素

struct Pixel
{
    int m_nX;
    int m_nY;

    Pixel(int x, int y)
    {
        m_nX = x;
        m_nY = y;
    }

    bool operator==(const Pixel& a) const{
        return a.m_nX == m_nX && a.m_nY == m_nY;
    }
};

您的示例可以简单得多:尝试将两个
像素
对象相互比较。这就是问题所在,
像素
没有比较运算符。
struct Pixel
{
    int m_nX;
    int m_nY;

    Pixel(int x, int y)
    {
        m_nX = x;
        m_nY = y;
    }

    bool operator==(const Pixel& a) const{
        return a.m_nX == m_nX && a.m_nY == m_nY;
    }
};