class within a class accessing accessing other class within the parent class

I have some code
I want to keep my class from doing too many task
I decide to make multiple class with specific task

Just imagine I have this kind of situation
I want to do

 
Rooms[0].people[0].buydrink();


but the class doesn't know which vendingMachine is it
how can I make it possible that every person in people array in
for example room[0] know which vendingMachine is in the room ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Room {
	
	class VendingMachine {
		
	} VendingMachine;
	
	class person {
	public:
		void buydrink(){
			/* How can I access vending machine ? */
		}
		
	};
	
	vector<person> people;
};

vector<Room> Rooms;


if I use static it will be like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Room {
	
	class VendingMachine {
		
	} VendingMachine;
	
	class person {
		static VendingMachine * VM;
	public:
		person( VendingMachine * _VM ){
			VM = _VM;
		}
		
		void buydrink(){
			*VM /*access to VendingMachine*/
		}
		
	};
	
	vector<person> people;
};

vector<Room> Rooms;


but if this is the case. It will only work if there is only 1 Room existed...
So is there any kind of special static ?
or I have to have a pointer for every "person" ?
or are there any better solution ?


Topic archived. No new replies allowed.