棋盘.h
#ifndef BOARD_H
#define BOARD_H
#include "piece.h"
class Board
{
public:
Board(bool);
//Piece * getPiece(int x, int y){return &pieceboard[x][y];}
};
#endif
板.cpp
#include "Board.h"
Board::Board(bool fill)
{
...
};
给我错误:'Board' 没有命名类型。 用 gcc 编译它。
编辑:
在我注释掉#include "piece.h"之后编译的代码。显然它有一些未声明的类。
#ifndef PIECE_H
#define PIECE_H
#include "Board.cpp"
class Piece{
public:
virtual bool checkMove(int, int) =0;
bool movePiece(int, int);
int getX(){return x;}
int getY(){return y;}
char getChar(){return image;}
bool getWhite(){return isWhite;}
protected:
int x, y;
char image;
bool isWhite;
};
class Pawn : public Piece{
public:
Pawn(bool, int, int, Board); // ERROR: 'Board' has not been declared
bool checkMove(int, int);
private:
Board * board; }; // ERROR: 'Board' does not name a type
#endif
最佳答案
代码很好。我猜这个错误是由于“piece.h”中潜伏的东西造成的
关于c++ - “类”没有命名类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18063642/