首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

二元运算符重载 binary 'operator ==' has too few parameters,该如何解决

2012-02-29 
二元运算符重载 binary operator has too few parameters我想写一个==重载,判断两个对象是否相等。boo

二元运算符重载 binary 'operator ==' has too few parameters
我想写一个==重载,判断两个对象是否相等。
bool operator==(Edge e)
{
if((Edge::p1==e.p1 && Edge::p2==e.p2)||(Edge::p2==e.p1&& Edge::p1==e.p2))
return true;
else
return false;
}

报错:perator==的参数太少。怎么回事

[解决办法]
成员函数方式:

C/C++ code
// declarationbool Edge::operator==(const Edge& e) const;// definationbool Edge::operator==(const Edge& e) const{ if((p1==e.p1 && p2==e.p2) ¦¦ (p2==e.p1 && p1==e.p2))     return true; else     return false; } 

热点排行