Hello. I'm a C++ newbie and am trying to make a functional console RPG game as a hobby project. The code I'm having a problem with allows the players to move through rooms, similar to an old text adventure game. I realize it's probably inefficient, but I've only been learning for a couple of weeks now.

I'm using Visual C++ 2008 Express. The code is below:

// Moving Through a Map
// Adventure-game style!

#include <iostream>
#include <string>
#include <vector>
using namespace std;

// Room class - defines a object representing rooms the player moves through
class Room {
	short int northConnectionID;
	short int southConnectionID;
	short int eastConnectionID;
	short int westConnectionID;
	string description;
	int roomID;

	Room(int roomID, int n, int s, int e, int w, string desc);
	int GetNorthConnection();
	int GetSouthConnection();
	int GetEastConnection();
	int GetWestConnection();
	string GetDescription();
	int GetRoomID();

Room::Room(int roomID, int n, int s, int e, int w, string desc) {
	northConnectionID = n;
	southConnectionID = s;
	eastConnectionID = e;
	westConnectionID = w;
	description = desc;

int Room::GetNorthConnection() {
	return northConnectionID;

int Room::GetSouthConnection() {
	return southConnectionID;

int Room::GetEastConnection() {
	return eastConnectionID;

int Room::GetWestConnection() {
	return westConnectionID;

string Room::GetDescription() {
	return description;
// Player class - simple class defining the player
class Player {
	int location;
	Player(int startingLocation);
	int GetLocationID();

Player::Player(int startingLocation) {
	location = startingLocation;

int Player::GetLocationID() {
	return location;

// global functions
int Move(int roomID, vector<Room> map, Player& p, char direction);
vector<Room> ConstructMap();
// Main function
int main() {
	vector<Room> map = ConstructMap();
	Player player(1);
	char choice;
	string desc;
	do {
		cout << "Move in what direction? (n/s/e/w): ";
		cin >> choice;
		Move(player.GetLocationID(), map, player, choice);
	} while (choice == ('n' || 's' || 'w' || 'e'));

	return 0;
int Move(int roomID, vector<Room> map, Player& p, char direction) {
	int pNorthConnection, pSouthConnection, pEastConnection, pWestConnection;
	string nDesc, sDesc, eDesc, wDesc;
	// Determines the player's location
	for (int i = 0; i < map.size(); ++i) {
		if (map[i].GetRoomID() == p.GetLocationID())
			Room pLoc = map[i];

	// Determines the player's location's connections, if any
	for (int i = 0; i < map.size(); ++i) {
		if (map[i].GetNorthConnection() != 0) {
			pNorthConnection = map[i].GetNorthConnection();
			nDesc = map[i].GetDescription();

		if (map[i].GetSouthConnection() != 0) {
			pSouthConnection = map[i].GetSouthConnection();
			sDesc = map[i].GetDescription();

		if (map[i].GetEastConnection() != 0) {
			pEastConnection = map[i].GetEastConnection();
			eDesc = map[i].GetDescription();

		if (map[i].GetWestConnection() != 0) {
			pWestConnection = map[i].GetWestConnection();
			wDesc = map[i].GetDescription();

	// Constructs the final description, moves the player, if possible, 
    // else lets the player know the move is impossible.
	if (direction == 'n' && (pNorthConnection != 0)) {
		cout << nDesc;
		return pNorthConnection;
	else if (direction == 's' && (pSouthConnection != 0)) {
		cout << sDesc;
		return pSouthConnection;
	else if (direction == 'e' && (pEastConnection != 0)) {
		cout << eDesc;
		return pEastConnection;
	else if (direction == 'w' && (pWestConnection != 0)) {
		cout << wDesc;
		return pWestConnection;
	// Returns 0 if the move is impossible.
	return 0;

Vector<Room> ConstructMap() {
	vector<Room> map;
	// Hard-coded map for the test environment.
	Room r1(1, 0, 2, 0, 0, "A damp corrider. There is a doorway to the south.");
	Room r2(2, 1, 0, 0, 0, "A grand hall.  There is a doorway to the north.");


	return map;

The compiler outputs the following errors:
1>c:\...\main.cpp(147) : error C2143: syntax error : missing ';' before '<'
1>c:\...\main.cpp(147) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\...\main.cpp(147) : error C2143: syntax error : missing ';' before '{'
1>c:\...\main.cpp(147) : error C2447: '{' : missing function header (old-style formal list?)

I've spend a couple hours looking for the missing ';' and simply can't find it. Am I missing where it should be, or is this explained by something else?

Any assistance is appreciated! Thanks! :)

Recommended Answers

All 3 Replies

'Vector' - 'vector'

What a silly mistake on my part. With the following correction vector<Room> ConstructMap() { , the compiler now outputs a more cryptic error message:

1>main.obj : error LNK2019: unresolved external symbol "public: int __thiscall Room::GetRoomID(void)" (?GetRoomID@Room@@QAEHXZ) referenced in function "int __cdecl Move(int,class std::vector<class Room,class std::allocator<class Room> >,class Player &,char)" (?Move@@YAHHV?$vector@VRoom@@V?$allocator@VRoom@@@std@@@std@@AAVPlayer@@D@Z)

I know that means I'm not giving the linker information it needs, but I'm not quite sure where to start to fix it.

i dont think you have provided a body for the method 'GetRoomID'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.