Skip to main content
GameDev.net gamedev.net
🔒 Locked

operator== two arguments

Started by FooLeo Sep 25, 2010 at 12:36 PM 2 replies 800+ views
Original Post
FooLeo
FooLeo
I am getting an error when I try to define an == function.
Are you even alowed to do this in a Header file?

'bool operator==(Position&)' must take exactly two arguments
||=== Build finished: 1 errors, 0 warnings ===|



#ifndef POSITION_H_INCLUDED
#define POSITION_H_INCLUDED



struct Position{
float Xpos;
float Ypos;
};

bool operator==(Position& other) {
return (Xpos == other.Xpos && Ypos == other.Ypos);
}



#endif // POSITION_H_INCLUDED
karwosts
karwosts
Your operator needs to be a part of the struct definition (before the close brace). Right now its just floating out in the ether as a function that compares other to nothing.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
SiCrane
SiCrane
It doesn't need to be part of your Position type, but if it isn't then, as the error says, the function needs to take two arguments: one for the left hand side of the == and one for the right hand side.
iMalc
iMalc
See this page for the two different ways to overload that operator.

Don't forget your const-correctness.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.