After learning more about classes and pointers, I refactored a program I had and wiped out > 200 lines of code, in the process creating two other classes, Location
and Piece
. The problem is, after getting everything to compile, the linker complains that the constructor for Piece
is defined multiple times, with a load of errors:
In function 'Piece': board.o
multiple definition of 'Piece::Piece(int)` char_traits.h
In function 'Piece': board.o
multiple definition of 'Piece::Piece(int)` piece.cpp
In function 'Piece': player.o
multiple definition of 'Piece::Piece(int)` piece.cpp
In function 'Piece': player.o
multiple definition of 'Piece::Piece(int)` piece.cpp (yes, same exact error!)
In function 'Piece': refereee.o
multiple definition of 'Piece::Piece(int)` char_traits.h
In function 'Piece': referee.o
multiple definition of 'Piece::Piece(int)` piece.cpp
...
When I click on the error for char_traits.h
, it brings me to this:
static size_t
length(const char_type* __s) //error points here to line 262
{ return __builtin_strlen(__s); }
Another char_traits.h
brings me to
static int
compare(const char_type* __s1, const char_type* __s2, size_t __n) //line 258, error points here too
{ return __builtin_memcmp(__s1, __s2, __n); }
And just so you know, location.h is the only thing that includes piece.h (well, other files include piece.h indirectly from location including piece.h), board.h is the only thing that includes location.h, and a bunch of classes include board.h
I tried changing the header guard to _OTHELLO_PIECE_H
, and tried renaming the class to OPiece (via the IDE). Neither fixed the problem.
The funny thing is, one of the errors has an "in function 'OPiece':", and after that my IDE puts chatter.o
, even though neither chatter.h nor chatter.cpp includes anything that includes OPiece.
Any idea what might be causing this redefinition error?