Here is my source code. It's a simple matrix class
I want to implement + operator overloading for matrix addition.
But this code is not work. I have no idea what to do at all.
Entire designing is wrong for this?
(Sorry for poor english, I'm not a native)
#include <iostream>
template<typename T, int r, int c>
struct Mat {
T arr[r][c];
void print_all() {
for (int i = 0; i < r ; i++) {
for (int j = 0; j < c ; j++) {
std::cout << arr[i][j] << ' ';
}
std::cout << '\n';
}
}
void get_rows_count() {
return r;
}
void get_columns_count() {
return c;
}
void print_rows_values(int rows_index) {
for (int i = 0; i < c ; i++) {
std::cout << arr[rows_index][i] << ' ';;
}
std::cout << '\n';
}
void print_columns_values(int columns_index) {
for (int i = 0; i < r ; i++) {
std::cout << arr[i][columns_index] << '\n';;
}
}
// how can I modify below?
Mat operator+(Mat& right) {
Mat<T, r, c> temp;
for (int i = 0; i < r ; i++) {
for (int j = 0; j < c ; j++) {
temp.arr[i][j] = arr[i][j] + right[i][j];
}
}
return temp;
}
};