Help with basic syntax for == operator

Can you please confirm the syntax for this "==" operator is correct based on a class "class Point" as indicated below.

I attempted to run a unit test like this:
TEST(equality, Point)
{
CHECK_EQUAL(Point(1,2) Point(1,2));
}
Then in the compiler, I get this error:

Severity Code Description Project File Line Suppression State
Error C2676 binary '==': 'Point' does not define this operator or a conversion to a type acceptable to the predefined operator Assign1 C:\Users\myuser\source\repos\Assign1\TestPoint.cpp 7


On my header file for Point.h, I understand I need
to create a "==" operator.

class Point
{
public:
Point(int x, int y);
bool operator == (Point & Point) const; //<== Is this correct?

private:
int x;
int y;
};

//now on the Point.cpp file:
//(...)

bool Point::operator==(Point& Point) const
{
//What should I write here for this comparison?

return false;
}

[/code]
What makes two points the same?

Are they the same if they're in different places?

Is point (4,5) the same as point (8,9)?

How can you tell?
>CHECK_EQUAL(Point(1,2) Point(1,2));
I would have expected a comma there


> bool operator == (Point & Point) const; //<== Is this correct?
that signature tells you that you are modifying the second argument, that if you do a == b for some reason `b' changes, ¿does that make sense to you?
and then it fails to compile because you try to pass a temporary there.

bool operator==(const Point &) const;
Topic archived. No new replies allowed.