[Solved] How to set a matrix as a parameter to a function


You can represent the matrix as a vector<vector<int> >. Try something like this:

#include <vector>

using namespace std;

void myFunction(const vector<vector<int> >& matrix) {
  // do something w/ matrix passed in...
}

int main() {
  // create a 3x4 matrix initialized to all zero
  const size_t rowCount = 3;
  const size_t colCount = 4;
  vector<vector<int> > matrix(rowCount, vector<int>(colCount, 0));

  // pass matrix to a function
  myFunction(matrix);

  return 0;
}

1

solved How to set a matrix as a parameter to a function