[computer-go] C++: #include vs .h files
Dave Denholm
ddenholm at esmertec.com
Thu Aug 10 02:04:33 PDT 2006
Peter Drake <drake at lclark.edu> writes:
> That mostly worked, but I have a more subtle problem.
>
> I have two classes, BitBoard and BoardState. Each needs to know about
> the other because the other appears in field declarations or method
> signatures. If I put
>
> #include "BoardState.h"
>
> in BitBoard.h and vice versa, there is obviously a circularity. How
> to get around this?
>
The earlier suggestion of surrounding the body of a header file with
an ifdef would fix this.
BitBoard.h has
#ifndef BITBOARD_H
#define BITBOARD_H
#include <BoardState.h>
...
#endif
and similarly for BoardState.h
Then whichever you include first will include the other, but it will
not continue to recurse because when the second re-includes the first,
it will find nothing to do because its guard is already defined.
dd
--
Dave Denholm <ddenholm at esmertec.com> http://www.esmertec.com
More information about the computer-go
mailing list