在学习了关于类和指针的更多信息之后,我重构了一个程序并清除了> 200行代码,并创建了另外两个类Location
和Piece
。问题是,让一切来编译后,链接器抱怨说,为Piece
的构造函数定义多次,错误的负载:多重定义错误
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
...
当我点击了错误char_traits.h
,它带给我这个:
static size_t
length(const char_type* __s) //error points here to line 262
{ return __builtin_strlen(__s); }
另一个char_traits.h
使我
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); }
而只是让你知道,location.h是唯一个(包括piece.h在内的其他文件间接包含piece.h),board.h是唯一包含location.h的类,并且一堆类包含board.h
我尝试将头文件后卫更改为_OTHELLO_PIECE_H
,并尝试将该类重命名为OPiece(通过IDE)。没有解决问题。
有趣的是,其中一个错误有一个“in function'OPiece':”,之后我的IDE放入chatter.o
,即使chatter.h和chatter.cpp都没有包含任何包含OPiece的东西。
任何想法可能会导致此重新定义错误?
您是否尝试重建整个项目?有关OPiece的错误消息可能是由过时的预编译头引起的。 – Vlad 2010-10-29 17:34:13