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?
>CHECK_EQUAL(Point(1,2) Point(1,2));
I would have expected a comma there
> booloperator == (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.