I have an object SeatSelection. In this object, I declare a array of integer arrays as follows
int *rows[25];
My SeatSelection constructor initializes the rows variable as follows:
SeatSelection::SeatSelection(int start, int range){
this->range = range;
this->start = start;
for(int i = 0; i < range; i++){
rows[i] = new int[10];
for(int j = 0; j < 10; j++)
rows[i][j] = (j+1);
}
}
In theory, I should now have an array of integer arrays of size 10 right?
In my driver class,
I am declaring two SeatSelection objects, both with different paramaters:
SeatSelection premium(1,5);
SeatSelection regular(6, 15);
premium should have 5 rows of 10 seats each = 50 seats.
regular should have 15 rows of 10 seats each = 150 seats.
Through some debugging, I found out that both these distinct SeatSelection objects are sharing the same rows pointer/array. I did not declare this variable as static. Why is this happening?
std::vector?std::vector. Our arrays must be done "by hand."rowswas a global, it actually did have implicitstaticlifetime!