头文件中的类声明应该包含哪些内容? < C++中的类声明应该怎么做?

头文件中的类声明应该包含哪些内容? < C++中的类声明应该怎么做?,c++,design-patterns,scoping,C++,Design Patterns,Scoping,例如,我在头文件中包含以下内容: class BoardState { public: BoardState(); bool HasWon() const; bool HasMoves() const; bool MakeMove(const int column); bool UndoMove(const int column); const Chip (&grid() const)[kGridHeight][kGridWidth] { return gr

例如,我在头文件中包含以下内容:

class BoardState {
 public:
  BoardState();

  bool HasWon() const;
  bool HasMoves() const;
  bool MakeMove(const int column);
  bool UndoMove(const int column);

  const Chip (&grid() const)[kGridHeight][kGridWidth] { return grid_; }
  const Chip lastplayer() const { return lastplayer_; }

 private:
  Chip grid_[kGridHeight][kGridWidth];
  Chip turn_;
  Chip lastplayer_;
  int lastmove_;
  DISALLOW_COPY_AND_ASSIGN(BoardState);
};

此类的cpp文件定义了许多附加的小型实用程序函数、类型和枚举。所有这些都应该在类声明的私有部分中定义吗?

通常最好将辅助功能留在类之外。这样,就可以重载类似类和类似功能的函数


作为实现的一部分,不会/不应该为任何其他组件做任何事情的小型实用程序应该是
private
成员。

通过返回内部数据成员
grid
您已经突破了所有抽象。看哪一个详细说明了这一点。
class Foo{/*…*/}不是类声明,而是类定义。类声明类似于
classfoo(请注意缺少的类主体),有时也称为转发声明。在类定义中定义还是仅仅声明成员函数是一个单独的问题。