Reputation:
I am using this class below
template<typename T>
class array_2d
{
public:
std::size_t data;
std::size_t col_max;
std::size_t row_max;
std::vector<T> a;
array_2d(std::size_t col, std::size_t row) : data(col*row), col_max(col), row_max(row), a(data)
{}
T& operator()(std::size_t col, std::size_t row)
{
assert(col_max > col && row_max > row);
return a[col_max*col + row];
}
};
And initializing it as so
array_2d<CString> tableData(5, 2);
for(int r = 0; r < 5; r++)
for(int c = 0; c < 2; c++)
tableData(r, c) = "Test";
And keep coming back that I am exceeding the bounds of a vector. I have been trying for hours to get a successful 2-dimensional CString array.
Upvotes: 0
Views: 105
Reputation: 39370
tableData(r, c) = "Test";
vs
T& operator()(std::size_t col, std::size_t row)
Surely that can't work.
Upvotes: 1