C++ 比较两个用户定义的类型向量
我尝试使用!=,比较两个向量,但VS2015显示了这些错误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 &&
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;
}
};