main.cpp(147) : error C2143: syntax error : missing ';' before '<'

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2007
Posts: 6
Reputation: jdphenix is an unknown quantity at this point 
Solved Threads: 0
jdphenix's Avatar
jdphenix jdphenix is offline Offline
Newbie Poster

main.cpp(147) : error C2143: syntax error : missing ';' before '<'

 
0
  #1
Apr 21st, 2008
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:

  1. // Moving Through a Map
  2. // Adventure-game style!
  3.  
  4. #include <iostream>
  5. #include <string>
  6. #include <vector>
  7. using namespace std;
  8.  
  9. // Room class - defines a object representing rooms the player moves through
  10. class Room {
  11. private:
  12. short int northConnectionID;
  13. short int southConnectionID;
  14. short int eastConnectionID;
  15. short int westConnectionID;
  16. string description;
  17. int roomID;
  18.  
  19. public:
  20. Room(int roomID, int n, int s, int e, int w, string desc);
  21. int GetNorthConnection();
  22. int GetSouthConnection();
  23. int GetEastConnection();
  24. int GetWestConnection();
  25. string GetDescription();
  26. int GetRoomID();
  27. };
  28.  
  29. Room::Room(int roomID, int n, int s, int e, int w, string desc) {
  30. northConnectionID = n;
  31. southConnectionID = s;
  32. eastConnectionID = e;
  33. westConnectionID = w;
  34. description = desc;
  35. }
  36.  
  37. int Room::GetNorthConnection() {
  38. return northConnectionID;
  39. }
  40.  
  41. int Room::GetSouthConnection() {
  42. return southConnectionID;
  43. }
  44.  
  45. int Room::GetEastConnection() {
  46. return eastConnectionID;
  47. }
  48.  
  49. int Room::GetWestConnection() {
  50. return westConnectionID;
  51. }
  52.  
  53.  
  54. string Room::GetDescription() {
  55. return description;
  56. }
  57. // Player class - simple class defining the player
  58. class Player {
  59. private:
  60. int location;
  61. public:
  62. Player(int startingLocation);
  63. int GetLocationID();
  64. };
  65.  
  66. Player::Player(int startingLocation) {
  67. location = startingLocation;
  68. }
  69.  
  70. int Player::GetLocationID() {
  71. return location;
  72. }
  73.  
  74.  
  75. // global functions
  76. int Move(int roomID, vector<Room> map, Player& p, char direction);
  77. vector<Room> ConstructMap();
  78. // Main function
  79. int main() {
  80. vector<Room> map = ConstructMap();
  81. Player player(1);
  82. char choice;
  83. string desc;
  84. do {
  85.  
  86. cout << "Move in what direction? (n/s/e/w): ";
  87. cin >> choice;
  88. Move(player.GetLocationID(), map, player, choice);
  89. } while (choice == ('n' || 's' || 'w' || 'e'));
  90.  
  91. return 0;
  92. }
  93. int Move(int roomID, vector<Room> map, Player& p, char direction) {
  94. int pNorthConnection, pSouthConnection, pEastConnection, pWestConnection;
  95. string nDesc, sDesc, eDesc, wDesc;
  96. // Determines the player's location
  97. for (int i = 0; i < map.size(); ++i) {
  98. if (map[i].GetRoomID() == p.GetLocationID())
  99. Room pLoc = map[i];
  100. }
  101.  
  102. // Determines the player's location's connections, if any
  103. for (int i = 0; i < map.size(); ++i) {
  104. if (map[i].GetNorthConnection() != 0) {
  105. pNorthConnection = map[i].GetNorthConnection();
  106. nDesc = map[i].GetDescription();
  107. }
  108.  
  109. if (map[i].GetSouthConnection() != 0) {
  110. pSouthConnection = map[i].GetSouthConnection();
  111. sDesc = map[i].GetDescription();
  112. }
  113.  
  114. if (map[i].GetEastConnection() != 0) {
  115. pEastConnection = map[i].GetEastConnection();
  116. eDesc = map[i].GetDescription();
  117. }
  118.  
  119. if (map[i].GetWestConnection() != 0) {
  120. pWestConnection = map[i].GetWestConnection();
  121. wDesc = map[i].GetDescription();
  122. }
  123. }
  124.  
  125. // Constructs the final description, moves the player, if possible,
  126. // else lets the player know the move is impossible.
  127. if (direction == 'n' && (pNorthConnection != 0)) {
  128. cout << nDesc;
  129. return pNorthConnection;
  130. }
  131. else if (direction == 's' && (pSouthConnection != 0)) {
  132. cout << sDesc;
  133. return pSouthConnection;
  134. }
  135. else if (direction == 'e' && (pEastConnection != 0)) {
  136. cout << eDesc;
  137. return pEastConnection;
  138. }
  139. else if (direction == 'w' && (pWestConnection != 0)) {
  140. cout << wDesc;
  141. return pWestConnection;
  142. }
  143. // Returns 0 if the move is impossible.
  144. return 0;
  145. }
  146.  
  147. Vector<Room> ConstructMap() {
  148. vector<Room> map;
  149. // Hard-coded map for the test environment.
  150. Room r1(1, 0, 2, 0, 0, "A damp corrider. There is a doorway to the south.");
  151. Room r2(2, 1, 0, 0, 0, "A grand hall. There is a doorway to the north.");
  152.  
  153. map.push_back(r1);
  154. map.push_back(r2);
  155.  
  156. return map;
  157. }

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!
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 449
Reputation: Agni is a jewel in the rough Agni is a jewel in the rough Agni is a jewel in the rough 
Solved Threads: 70
Sponsor
Agni's Avatar
Agni Agni is offline Offline
Posting Pro in Training

Re: main.cpp(147) : error C2143: syntax error : missing ';' before '<'

 
0
  #2
Apr 21st, 2008
'Vector' - 'vector'
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 6
Reputation: jdphenix is an unknown quantity at this point 
Solved Threads: 0
jdphenix's Avatar
jdphenix jdphenix is offline Offline
Newbie Poster

Re: main.cpp(147) : error C2143: syntax error : missing ';' before '<'

 
0
  #3
Apr 21st, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 449
Reputation: Agni is a jewel in the rough Agni is a jewel in the rough Agni is a jewel in the rough 
Solved Threads: 70
Sponsor
Agni's Avatar
Agni Agni is offline Offline
Posting Pro in Training

Re: main.cpp(147) : error C2143: syntax error : missing ';' before '<'

 
0
  #4
Apr 21st, 2008
i dont think you have provided a body for the method 'GetRoomID'
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC