1

I am making a C++ program using Microsoft Visual Studio 2010.

When I add comments in the header file I get error messages on part of my code that is not included in the comment. If I remove the first two lines of comments under public, the errors under GameBoard(int p, int t) go away. If I remover all four comments under public: then the error under private: goes away.

Here are the error messages that I get:

  • Under GameBoard(int p, int t) I get an error under int that says Error: Expected an identifier. I also get an error under the comma that says Error: Expected a ')' And the last error I get is under the closing parenthesis that says Error: expected a ';'. But these three errors go away as soon as I remove the first two commented lines of the code shown below.

  • The other error I get is under private:, that says, Error: expected a declaration. This error goes away as soon as I remove all four commented lines under public:

Does anyone know why this is happening, commented lines aren't supposed to have any effect on the code. I've tried using the other kind of comment /* */ but the same thing happens.

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 
};
Thibault
  • 1,566
  • 15
  • 22
  • 4
    If `Tile.h` is anything like this header, I'd start by making sure the class declarations **all** end with `};`, not just `}`. And the placement and usage of your `using namespace std;` in this is dreadful, *especially* if this is a header file. [**Read this**](http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice). – WhozCraig May 24 '14 at 22:12
  • My original code does have it, I just forgot to add it here. Thanks for pointing that out, added it. – user3672615 May 24 '14 at 22:18
  • 3
    It's going to be a missing semicolon or missing brace somewhere... – Kerrek SB May 24 '14 at 22:20

2 Answers2

0

Same thing happened to me once, I was trying to copy/paste codes from devC++ to VS2008. Maybe pasting somthing couses the problem.

Sachamora
  • 479
  • 2
  • 13
0

Perhaps you have a bogus character in your source somewhere, like a UTF-8 BOM in the middle of it or something.

Try copying your code back out of Stack Overflow and pasting it over the top of your original - does that make a difference? (Or even just manually re-typing it - it's only a few lines.)

RichieHindle
  • 272,464
  • 47
  • 358
  • 399