I’m implementing a chess game in c++ and some of the classes are “Board” and “Piece”.
There are classes “Rook”, “King”,… etc inherited from “Piece”.
So a board is a 2D array of pieces and so board.h has piece.h included.
For recent development (on implementing moves) I wanted to give the pieces access to the board.
so in piece.h I included board.h.
This now creates above error.
Some code:
//Function in piece.h
#include "board.h"
bool Piece::move( int toX, int toY, bool enemyPawn, const Board & b )
Error: Board does not name a type Error: ISO C++ forbids declaration of ‘b’ with no type [-fpermissive]
Since move only uses a reference, you could definitely avoid the inclusion of board.h and only forward declare your class Board. If you really need to have piece know about board and board know about piece, you could declare an interface class to Board (pure abstract) and include that interface instead of the board making sure to make board derive from the interface – Martin just now edit