I am trying to write a small C++ library to do simple matrix calculations. It consists of a Matrix class with static member functions altering given matrices.
I have one function which adds a scalar to each element, however the loop isn't working:
// Member function to add a scalar to the matrix
void Matrix::add_scal(double** arr, double s) {
for (size_t x = 0; x < sizeof(arr) / sizeof(*arr); ++x) {
Serial.println("test");
for (size_t y = 0; y < sizeof(*arr) / sizeof(**arr); ++y) {
arr[x][y] += s;
}
}
}
"Test" is only printed once and the inner loop isn't run at all. Here is the function I use to create a matrix:
double** Matrix::init(int rows, int cols) {
double** temp = new double*[rows];
for (int i = 0; i < rows; i++) {
temp[i] = new double[cols];
for (int j = 0; j < cols; j++) {
temp[i][j] = 0.0;
}
}
return temp;
}
The following two lines create a matrix and are supposed to add a scalar to it:
double** test = Matrix::init(3, 3);
Matrix::add_scal(test, 2.5);