vector in a vector

I have a reservation system, I have a 3 vectors. a User vector, a Bookings vector, and a Reservation vector.

The Bookings vector needs to be in the User vector which then needs to be in the Reservation vector.

how would I declare them?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class Rates{
public:
	Rates();
	int monthRate;
	int weekRate;
	int dayRate;
};
Rates::Rates(){
};
class Bookings{
public:
	Bookings();
	string name;
	int date;
	int start_date;;
	int length_of_stay;
	double price;
};

class Users{
public:
	Users();
	string username;
};

class Reservation{
	Reservation();
};

Bookings::Bookings(){
};

Users::Users(){
};


Reservation::Reservation(){
};


vector<Bookings> bookVector;
vector<Users> userVector;
vector<Reservation> ReservationVector;



Make the bookings vector an object in the reservation vector.

1
2
3
4
5
6
7
class Reservation{
    Reservation();
public:
    vector<Bookings> bookVector;
}

vector<Reservation> ReservationVector;


now refer to them like:
1
2
3
4
for (vector<Reservation>::iterator i = ReservationVector.begin(); i < ReservationVector.end(); i++)
    for (vector<Bookings>::iterator j = i->bookVector.begin(); j<i->bookVector.end();j++)
        cout << j->date; //Will output the date of each booking.
        



Otherwise if you want a vector in a vector (2D), they need to be of the same type:
vector<vector<Reservation> > Reservations2D;
Last edited on
Topic archived. No new replies allowed.