以下錯誤總是指向我的列表。C++ List Unique()函數
在我的類文件
Point3D operator==(const Point3D &p1) const;
在我.cpp文件
bool operator==(Point3D &p1, Point3D &p2)
{
if (p1.getX() == p2.getX() && p1.getY() == p2.getY() && p1.getZ() == p2.getZ())
return true;
else
return false;
}
在我的主文件
//declaration
list<Point3D> l_3D;
l_3D.unique(); <-- the error point to this
錯誤消息
..... In member function 'void std::list<_Tp,_Alloc>::unique() [with_Tp = Point3D,_Alloc = std:: allocator<Point3D>]:
Instantiated from here
error: could not convert 'Point3D::operator==(const Point3D&) const (((const Point3D&)((const Point3D*)__next. std::_List_iterator<_Tp>::operator*[with_Tp = Point3D]())))' to 'bool'
對於那裏的善良的靈魂,我提前感謝你。
此外,而不是'if(some_bool_expression)返回true;否則返回false;',只是有'返回some_bool_expression;'更具慣用性'' –
當人們寫'if(a)返回true時,總會讓我不寒而慄;否則返回false;'而不僅僅是'返回'; : - } –