![]() |
| | #1 |
| Registered User Join Date: May 2004
Posts: 3
| Object array. Probelm accessing methods Code:
// main .cpp file
#include <iostream>
#include "Room.h"
using namespace std;
CRoom Rooms[14]={1,2,3,4,5,6,7,8,9,10,11,12,13,14};
void main()
{
title();
Rooms[1].set_door(0,2,0,1);
Rooms[2].set_door(7,1,9,11);
Rooms[3].set_door(9,0,0,10);
Rooms[4].set_door(0,10,0,0);
// ...etc etc
// another .cpp file
#include <iostream>
#include "Player.h"
using namespace std;
CPlayer::~CPlayer()
{
}
void CPlayer::move(int direction)
{
Rooms[1].set_door(1,2,3,4);
// errors occurs when this line is include e.g.
// 'Rooms' : undeclared identifier
// subscript requires array or pointer type
// left of '.set_door' must have class/struct/union type
}
|
| Bean is offline | |
| | #2 |
| Toaster Join Date: Aug 2001
Posts: 2,686
| In your other source file, put: extern CRoom Rooms[14]; This lets the compiler know that Rooms has been declared and defined elsewhere. Also, 'void main' is bad, 'int main' is good. For a thorough explanation of this, consult the FAQ. Cheers |
| Zach L. is offline | |
| | #3 |
| Registered User Join Date: May 2004
Posts: 3
| erm, I get less errors now. Here the code as it looks now: Code: #include <iostream>
#include "Player.h"
extern CRoom Rooms[14]; // newly added
using namespace std;
CPlayer::~CPlayer()
{
}
void CPlayer::move(int direction)
{
Rooms[1].set_door(1,2,3,4);
}
missing ';' before identifier 'Rooms' unexpected end of file found I tried editing it and moving it around. Am I just being a bit stupid and putting it in the wrong place or something? Last edited by Bean; 05-02-2004 at 09:54 PM. |
| Bean is offline | |
| | #4 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,630
| > extern CRoom Rooms[14]; // newly added Put this in rooms.h Then #include "rooms.h" |
| Salem is offline | |
| | #5 |
| Registered User Join Date: May 2004
Posts: 3
| ah... I was being a bit stupid. Works perfectly now. Thanks! |
| Bean is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| question about multidimensional arrays | richdb | C Programming | 22 | 02-26-2006 09:51 AM |
| A question about constructors... | Wolve | C++ Programming | 9 | 05-04-2005 04:24 PM |
| Merge sort please | vasanth | C Programming | 2 | 11-09-2003 12:09 PM |
| Creating an array of object pointers | Unregistered | C++ Programming | 2 | 10-08-2001 10:01 PM |
| Bitmap from array to an object | steve_i83 | Windows Programming | 2 | 09-28-2001 08:16 AM |