C++ ';类别';不命名类型
董事会 Board.cppC++ ';类别';不命名类型,c++,constructor,header,C++,Constructor,Header,董事会 Board.cpp #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 告诉我错误:“Board”没有命名类型。 用gcc编译它 编辑: 我注释掉#include“piece
#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
告诉我错误:“Board”没有命名类型。
用gcc编译它
编辑:
我注释掉#include“piece.h”后编译的代码。显然它有一些未声明的类
#include "Board.h"
Board::Board(bool fill)
{
...
};
代码很好。我猜这个错误是由于“piece.h”中潜藏了一些东西
piece.h
包含什么?让我们看看内容。似乎是循环的#includes
。piece.h
是否包含对板的引用或其他有趣的内容?故障可能在那里。分号定义构造器后不需要code>,错误指向的是哪个文件的哪一行?为什么要用GCC编译.cpp
它?这不是问题的解决方案,应该是注释而不是答案。但是考虑到问题在于未提供的一段代码这是最接近可能给出的答案。他是对的。在我注释掉该包含内容后编译的代码。
#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