Mat[][] doesn't make sense, sorry. Aside from it not being valid syntax, your Mat function doesn't return anything. It just prints things.
You have to call your Mat function like any other function, something like
1 2
std::vector<std::vector<int>> result;
Mat(result, nbits); // or my_ham_object.Mat(result, nbits); if outside of a class
To multiple a matrix (represented by a 2d std::vector) by a column vector (represented by a 1d std::vector), you have to manually do the multiplies yourself with for loops.
If you want to be fancy, you could define an operator overload.
I'm sorry, I don't understand what you're actually asking at this point. I assume it's still not compiling?
You changed for (int a = 0; a < 3; a++) {
to for (constauto& row : Mat) {,
but you're still trying to use a variable that no longer exists, called "a".
If you need to keep track of the index, I don't suggest using a for-each loop.
I assume there's 3 rows? As in, Mat.size() == 3? Your use of magic numbers is a bit confusing.
1 2 3 4 5 6 7 8 9 10
char synd[3];
for (int a = 0; a < Mat.size(); a++) {
auto& row = Mat[a];
char result = 0;
for (int b = 0; b < 7; b++) {
result += (row[b] * decode[b]);
}
synd[a] = result % 2;
}
The common link that you are trying to glue between your two functions is a connection to your std::vector<std::vector<int>>& result.
I am assuming that when you first call your Mat function, you have an object of type std::vector<std::vector<int>> that is then correctly filled with appropriate values in a 2D way.
But now... your Decode function has no idea what your result matrix is. I never see where you declare an std::vector<std::vector<int>> object to actual use. This design is confusing. Should your Ham class contain a matrix?
If you need to pass in your matrix, then you need to either have it be a member of your Ham class, or you need to pass it in through the Decode function's parameters, like you did with your Mat function.