What should go into class declarations in header files?
What should go into a class declaration in C++?
For example, I have the following in a header file:
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_[kGridHeigh开发者_如何学运维t][kGridWidth];
Chip turn_;
Chip lastplayer_;
int lastmove_;
DISALLOW_COPY_AND_ASSIGN(BoardState);
};
The cpp file for this class defines many additional small utility functions, types, and enums. Should all of these also be defined in the private section of the class declaration?
It is usually best to leave auxiliary functionality outside the class. That way, you can overload the functions for similar classes and similar functionality.
Small utilities which are part of the implementation and won't/shouldn't do anything for any other component, though, should be private
members.
精彩评论