以下でこのクラスを使用しています
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];
}
};
そして、そのように初期化します
array_2d<CString> tableData(5, 2);
for(int r = 0; r < 5; r++)
for(int c = 0; c < 2; c++)
tableData(r, c) = "Test";
そして、私がベクトルの境界を超えていることを何度も繰り返します。私は、成功した 2 次元 CString 配列を取得するために何時間も試みてきました。