gpt4 book ai didi

C++ 编译器错误;我猜是命名空间问题

转载 作者:行者123 更新时间:2023-11-28 08:11:48 26 4
gpt4 key购买 nike

我收到的错误是“命名空间 ChessGame 中没有名为 detail 的成员。这是相关代码

//ChessPiece.h
namespace ChessGame
{

class ChessBoard;

namespace detail
{
class IChessPieceEnums{
public:
enum PieceType{PAWN, KNIGHT, BISHOP, ROOK, QUEEN, KING};
enum PieceDirection{ UP = 1 , DOWN = -1};
enum PieceId{ WHITE_PIECE_ID, BLACK_PIECE_ID };
};
}

//represents an abstract chess piece interface
class IChessPiece : public detail::IChessPieceEnums
{
public:
///...
}

} // end namespace


//GameBoard.h
#include "ChessPiece.h"
namespace ChessGame
{

class IChessPiece;

class ChessBoard
{
public:
/*********ERROR OCCURS ON THIS FUNCTION************/
bool isOccupiedWithEnemy(int row, int col,const ChessGame::detail::IChessPieceEnums::PieceId& pieceId);
}
}

有什么想法吗?

编辑:另一个最小的例子:

//片.h

#ifndef TestProject_C___Piece_h
#define TestProject_C___Piece_h

#include "Board.h"

namespace Foo {
namespace detail{
struct PieceEnums{
enum PieceID{ ID1, ID2 };
};
}

class Board;

class Piece{
public:
void foo(Board& b)const;
};
}
#endif

//板.h

 #ifndef TestProject_C___Board_h
#define TestProject_C___Board_h

#include "Piece.h"


namespace Foo {
class Piece;

class Board{
bool isOcc(int x, int y,const detail::PieceEnums::PieceID pid)const;
};
}

#endif

错误是“使用未声明的标识符详细信息”

请注意,这是跨多个文件的,所以可能是链接问题?

最佳答案

要直接指定所需的名称,请说detail::IChessPieceEnums::PieceId::ChessGame::detail::IChessPieceEnums::PieceId,但最好是以前的。但是,您现在的语法实际上也很好,因为如果找不到名称,搜索将在全局命名空间中恢复。

关于C++ 编译器错误;我猜是命名空间问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8866752/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com