【发布时间】:2014-07-14 01:08:11
【问题描述】:
我正在使用 Microsoft Visual Studio 2010 制作 C++ 程序。
当我在头文件中添加 cmets 时,我会收到关于未包含在注释中的部分代码的错误消息。如果我删除public 下的前两行cmets,GameBoard(int p, int t) 下的错误就会消失。如果我删除了public: 下的所有四个 cmets,那么private: 下的错误就会消失。
以下是我收到的错误消息:
在
GameBoard(int p, int t)下我在int下得到一个错误,上面写着Error: Expected an identifier.我也在逗号下得到一个错误,上面写着Error: Expected a ')'我得到的最后一个错误是在写着@ 的右括号下987654330@。但是,只要我删除下面显示的代码的前两行注释,这三个错误就会消失。我得到的另一个错误是在
private:下,也就是说,Error: expected a declaration.一旦我删除了public:下的所有四个注释行,这个错误就会消失
有谁知道为什么会这样,注释行不应该对代码产生任何影响。我试过使用另一种评论/* */,但同样的事情发生了。
using namespace std;
#include <string>
#include "Tile.h"
#include <iostream>
class GameBoard{
public:
// p = The number of players
// t = The number of tiles each player will play with.
GameBoard(int p, int t);
void init();
// Scan the board and see if any tiles would be exiled.
void checkExile();
// Clear the board of any tiles.
void clear();
private:
// The Game Board.
TileO board[12][12];
// Detained tiles. The height is determined by the number of players. Each player can detain up to three tiles.
TileO * detained[3];
// These are the tiles that are not in the game.
// All tiles start on the bench, where the player places them on the Home Base.
TileO bench[4][2][4];
int players; // Number of players
int tilesPlaying; // Number of tiles
};
【问题讨论】:
-
如果
Tile.h是这样的标题,我首先要确保类声明all 以};结尾,而不仅仅是}。你的using namespace std;的放置和使用是可怕的,尤其是如果这是一个头文件。 Read this. -
我原来的代码里有,只是忘了在这里加上。感谢您指出这一点,添加它。
-
某处缺少分号或大括号...