The following are errors that i don't understand what they are talking about:
Error 6 error C2510: 'directions' : left of '::' must be a class/struct/union c:\documents and settings\hirokachi\my documents\docs\important junk\textadventure\source\GameField.h 116
Error 4 error C2334: unexpected token(s) preceding '{'; skipping apparent function body c:\documents and settings\hirokachi\my documents\docs\important junk\textadventure\source\GameField.h 27
Error 5 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\hirokachi\my documents\docs\important junk\textadventure\source\GameField.h 27
//lines 26-27:
class commands {
enumchar { n, s, e, w } command;
};
//lines 58-62:
class GameField {
std::list<room> listOfRooms;
std::list<roomConnections> connections;
// lines 101-121:
void directionalMove () {
commands directions;
//Define the variable storeing player choice
char move;
//printRoomDesc (playerPosition.uniqueID);
//Tell the player they can move now.
std::cout << "Please enter a direction.\n";
//get direction from player.
std::cin >> move;
//Check if command is valid
if (directions::n == move) {
std::cout << "You did try to move North which means that I program correctly. Hurray for me!!!";
}
else {
std::cout << "You didn't try to move north you silly player. Boo, I don't know how to use enums to hold commands.";
}
}
};
if anyone can help or point me in the right direction it would be greatly appreciated.
-Hirokachi
PS: if you need any more information let me know and I will post it here as well. By the way, I am using windows XP sp3 with Microsoft V.S. Express 2010 as the IDE; I am not sure if this is the underling problem.
In my case, however the following errors are occurring:
Error 1 error C2510: 'directions' : left of '::' must be a class/struct/union c:\documents and settings\hirokachi\my documents\docs\important junk\textadventure\source\GameField.h 117
Error 2 error C2065: 'north' : undeclared identifier c:\documents and settings\hirokachi\my documents\docs\important junk\textadventure\source\GameField.h 117
The following is the new code in GameField.h of my project, which has been added for your convenience:
//lines 26-29
class commandList {
public:
enum { north, south, east, west };
};
//in Class GameField and lines 102-126
void directionalMove () {
commandList directions;
//Define the variable storeing player choice
char move;
//printRoomDesc (playerPosition.uniqueID);
//Tell the player they can move now.
std::cout << "Please enter a direction.\n";
//get direction from player.
std::cin >> move;
//Check if command is valid
if (directions::north == move) {
std::cout << "You did try to move North which means that I program correctly. Hurray for me!!!";
}
else {
std::cout << "You didn't try to move north you silly player. Boo, I don't know how to use enums to hold commands.";
}
//Move player into room from that direction.
//Print out new Room Description.
}
/*
* void generateGameMap (totalRooms, randomize):
* loads the list of rooms and generates
* gameMap connections between rooms and randomized
* start and end location.
*/
void generateGameMap (int totalRooms, bool randomize) {
//Load room description and name/id from file into the listOfRooms.
//for player input:
// for the total number of Rooms:
// Generate the connections between rooms
// Generate start and end positions and set in the room
// run test verify if connections create a route to start to end
// store as the current connected gameMap
// or load a pregenerated map of said size and store
}
Line 23: It's not clear what value you're expecting the user to enter. north, south, east, west, have the values 0,1,2,3 respectively. That's certainly not clear to the user at line 17 when you ask the user to enter a direction.
Be aware that you can assign character literal values to enums.
1 2 3 4 5
enum { north = 'n',
south = 's',
east = 'e',
west = 'w'
};
This makes for a more logical input from the user.
so commandList is not technically a class
Yes, commandList is technically a class. It contains one member variable, an anonymous enum.
Not to be confused with C++14 which has strongly typed enums: