我在尝试制作这个程序时遇到了一些问题。当我编译时它告诉我我有一个错误:第 49 行此文件内的一个声明中有多个类型。
#ifndef GRIDGAME_H
#define GRIDGAME_H
#include "GameType.h"
class GridGame {
public:
GridGame();
~GridGame();
enum GameType GetType() { return m_type; }
void OutputGreeting() const;
int NumPlayers() const;
char GetPlayerSymbol(int player) const;
int GetBoardSize() const;
/* Returns NULL on good move, else returns err string.
* Note that this check is game-neutral (at least for TTT and Reversi)
*/
const char *IsLegalMove(int player, int row, int col) const;
void OutputBoard() const;
protected:
GridGame(enum GameType type, const char *name, const char *playerSymbols, int boardSize);
void DoBasicMove(int player, int row, int col);
// The only data member that the subclassed games should really
// need full read/write access to, once game is set up.
char **m_board;
private:
enum GameType m_type;
const char *m_gameName;
int m_boardSize;
const char *m_playerSymbols;
};
#endif //GRIDGAME_H
我没有看到任何错误,任何人都可以帮助我吗?
编辑:第 49 行是最后一个带分号的花括号。
最佳答案
可能的情况是 enum GameType
没有正确声明,也就是说,您的 enum
可能是这样声明的:
enum GameType
{
First,
Second,
//...
Last
}
问题在于 enum
和任何类型声明都需要在其声明末尾使用分号 (;
),如下所示:
enum GameType
{
First,
Second,
//...
Last
};
关于C++ - 错误 : multiple types in one declaration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23666802/