I have a table object with the following header file:
#ifndef TABLE_H
#define TABLE_H
#include "Order.h"
#include "Waiter.h"
// 0 1 2 3
enum TableStatus { IDLE, SEATED, ORDERED, SERVED };
class Waiter; // to take care of circular reference.
class Table
{
private:
int tableId; // table number
const int maxSeats; // table seat capacity
TableStatus status; // current status, you can use assign like
// status = IDLE;
int numPeople; // number of people in current party
Order *order; // current party's order
Waiter *waiter; // pointer to waiter for this table
public:
Table(int tblid =0, int mseats = 0); // initialization, IDLE
void assignWaiter(Waiter *person); // initially no waiter
void partySeated(int npeople); // process IDLE --> SEATED
void partyOrdered(Order *order); // process SEATED --> ORDERED
void partyServed(void); // process ORDERED --> SERVED
void partyCheckout(void); // process SERVED --> IDLE
int getMaxSeats(void);
int getStatus(void);
};
#endif
in my main function, I need to declare an array of tables. But when I write, say, Table *table = new Table[10], every element of the array calls the default arguments in the constructor, and every table ends up with a constant maximum seat value of 0. I need to be able to individually call each of their constructors to have different values for the maxSeats.
The only solution I've been able to come up with so far is to declare an array of pointers to table objects, and then instantiate each one separately. This partially works, but the Waiter class mentioned in the code above accepts an array of Tables as an argument, and won't work if it's passed an array of Table pointers.
What process can i perform to end up with an array of Table objects with differing values for their maxSeats constant variable?
One more point of clarification: The array has to be dynamically created, so I can't just explicitly make 10 or however many calls to the constructor. I don't know in advance how large the array must be.
class Waiter;here is bad , Waiter.h should doclass Waiter;at least.