I'm trying to create a 2d Array class for different use cases where I know the size at compile time and that it won't change during runtime. IE setting up a grid for a battleships game.
current implementation works in both debug and release when using balanced 2d arrays such as 2 by 2, however when using unbalanced 2d arrays like 2 by 3 it will work in release but not in debug. I get expression: array subscript out of range when debugging
im using visual studio 2022 RC with std 20 enabled
header file
template <class T,unsigned int colSize,unsigned int rowSize>
class TwoDArray{
public:
TwoDArray(){
for (int i = 0; i < colSize; ++i) {
for (int j = 0; j < rowSize; ++j) {
matrix[i][j] = j;
std::cout << matrix[i][j] << " ";
}
std::cout << " " << i << std::endl;
}
}
private:
std::array<std::array<T, colSize>, rowSize> matrix;
}
in main
int main(){
auto p = TwoDArray<int,2 ,3>{};
return 0;
}
colSizeandrowSizein your for loops. The outer one should berowSize