Reputation: 35
I'm currently developing a text adventure game in C++, and I'm trying to use enum to save on code. However, I get these errors:
1>f:\ghosthouse\ghosthouse\source.cpp(3): error C2236: unexpected token 'enum'. Did you forget a ';'?
1>f:\ghosthouse\ghosthouse\source.cpp(3): error C2143: syntax error : missing ';' before '{'
1>f:\ghosthouse\ghosthouse\source.cpp(3): error C2447: '{' : missing function header (old-style formal list?)
Here's the code in question:
#include "Header.h"
enum gen_dirs {north, east, south, west};
enum gen_rooms {entrance, bathroom, livingroom, diningroom, abedroom, cupboard, kitchen, cbedroom};
...
And the relevant header file:
#define HEADER_H
#include <iostream> // For cin and cout
#include <string> // For strings
#include <vector> // For vectors (arrays)
using namespace std;
struct RoomStruct
{
// The room the player is currently in, and its interactive objects.
string roomName;
string size;
bool rustyKeyIn;
bool goldKeyIn;
bool copperKeyIn;
bool torchIn;
bool toyIn;
bool leverIn;
bool oldCheeseIn;
bool toyBoxIn;
bool skeletonIn;
bool ghostIn;
}
Would anyone be able to figure out what's wrong, because as far as I can tell (and by checking other adventure game scripts) this should be working.
EDIT: I'm a massive idiot. I stuck a single semicolon after the } at the very end of the header and it now runs fine. Sorry for wasting your time everyone...
Upvotes: 2
Views: 5671
Reputation: 7960
You're missing a semicolon at the end of the struct definition - last line of header file
Upvotes: 0
Reputation: 310950
I think you did not show all the header. It seems that the problem is in the header because there is no any syntaxical error in the enum definition.
Try to compile the program having this header and empty main function.
EDIT: You forgot to place a semicolon after a structure definition.
Upvotes: 1
Reputation: 1761
struct
definitions need to end in semicolons (that is, after the last curly brace).
Upvotes: 1
Reputation:
You forgot the ;
after the }
in RoomStruct
.
#define HEADER_H
#include <iostream> // For cin and cout
#include <string> // For strings
#include <vector> // For vectors (arrays)
using namespace std;
struct RoomStruct
{
// The room the player is currently in, and its interactive objects.
string roomName;
string size;
bool rustyKeyIn;
bool goldKeyIn;
bool copperKeyIn;
bool torchIn;
bool toyIn;
bool leverIn;
bool oldCheeseIn;
bool toyBoxIn;
bool skeletonIn;
bool ghostIn;
}; //<---------------------------------
-edit- in C you can write struct RoomStruct {int a, b; } room1, room2;
so whats happening in your code is it thinks you're trying to declare a variable called enum
which is a reserved keyword
semicolons are the source of a lot of problems. When in doubt check if you forgot a semicolon!
Upvotes: 2