I've got the following function defined in chess_location.h
:
inline chess_location operator+(chess_location lhs, const chess_coord& rhs);
and then, in chess_location.cpp
:
#include "chess_location.h"
chess_location operator+(chess_location lhs, const chess_coord& rhs) {
//function definition
}
and then am using this operator in my main()
in main.cpp
, like so:
#include "chess_location.h"
int main() {
chess_location_B = chess_location_A + chess_coord;
}
but, I'm getting a linker error saying that the operator couldn't be found:
error LNK2019: unresolved external symbol "class chess_location __cdecl operator+(class chess_location,class chess_coord const &)" (??H@YA?AVchess_location@@V0@ABVchess_coord@@@Z) referenced in function _main
It seems to me like the linker isn't connecting the declaration of the operator to the definition, but I'm not sure why. I suspect that I may have something wrong with my const
s. If I move the operator definition to main.cpp
, however, everything compiles and works fine.
Any idea where this error is coming from?