Answer the question
In order to leave comments, you need to log in
How to solve dynamic two dimensional array indexing error?
We need to find the smaller value in a dynamic two-dimensional array. By and large, the whole code is ready, but in the indexing places it gives the error C2676 "binary "[": "Matrix" does not define this operator or conversion to a type acceptable to the built-in operator"
Here is the code:
template<typename T, size_t rows, size_t cols>
inline int Matrix<T, rows, cols>::findSmallest(Matrix<T, rows, cols>& m)
{
int resNum = m[0][0];
for (size_t i = 0; i < rows; i++)
{
for (size_t j = 0; j < cols; j++)
{
if (m[i][j] < resNum)
{
resNum = m[i][j];
}
}
}
return resNum;
}
int findSmallest(Matrix<T, rows, cols>& m);
Answer the question
In order to leave comments, you need to log in
You work with matrix as if it were an array, but you don't have it as an array. Either redefine the [] operator, or somehow output from matrix to T**.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question