c++ - “类”没有命名类型

标签 c++ constructor header

棋盘.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/

相关文章:

c++ - 复制/move 省略与显式删除的复制/move 构造函数

Angular2 Http POST header 参数类型错误

编译C文件,运行它并使用CMAKE写入头文件

c++ - Visual Studio 2017 无法打开源文件 <windows.h>

c++ - C++ 容器可以包含模板对象吗?出现错误

c++ - 作为模板参数和签名的函数指针

c++ - 我可以从不同的线程调用 socket send() 吗?

java - 从字节数组创建对象(使用构造函数)

java - 将两个构造函数简化为一个

html - 为什么标题、<h1> <h2> 等会在文本周围创建额外的空间?