As suggested here I fixed my 2D array of numbers to make it work with Vector class.
Header file:
#include <vector>
typedef std::vector<int> Array;
typedef std::vector<Array> TwoDArray;
And here is how it's used:
TwoDArray Arr2D;
// Add rows
for (int i = 0; i < numRows; ++i) {
Arr2D.push_back(Array());
}
// Fill in test data
for (int i = 0; i < numRows; i++) {
for (int j = 0; j < numCols; j++) {
Arr2D[i].push_back(ofRandom(0, 10));
}
}
// Make sure the data is there
for (int i = 0; i < numRows; i++) {
for (int j = 0; j < numCols; j++) {
std::cout << Arr2D[i][j] << ' ';
}
std::cout << '\n';
}
My question is, how can I do the same for custom objects instead of int numbers? I've tried a changing int by MyObject and using push_back(new MyObject()); but it doesn't work properly when I try to access it's functions.
Thank you in advance.