Создал класс для создания и вывода одномерных ( как бы двумерных ) массивов
нужно научить класс складывать эти массивы
Как праивльно написать перегрузку для знака "+" сложение массивов

В функции надо добавить return this, т. к. возвращает Matrici, а не void
#include <iostream>
#include <iomanip>
#include <random>
using namespace std;
template<const size_t Rows, const size_t Columns>
class Matrix {
public:
Matrix() { for (auto& row : matrix_) for (auto& value : row) value = 0; }
void show(const streamsize width)const {
for (const auto& row : matrix_) {
for (const auto value : row) cout << setw(width) << value;
cout.put('\n');
}
}
void random_fill(int left, int right) {
Random_ rand;
for (auto& row : matrix_) for (auto& value : row) value = rand.next(left, right);
}
Matrix operator+(const Matrix& mx) {
Matrix<Rows, Columns> box = *this;
for (auto i = 0U; i < Rows; ++i) {
for (auto j = 0U; j < Columns; ++j) {
box.matrix_[i][j] += mx.matrix_[i][j];
}
}
return box;
}
private:
int matrix_[Rows][Columns];
class Random_ {
public:
Random_() {
random_device device;
random_generator_.seed(device());
}
int next(int first, int last) {
uniform_int_distribution<int> range(first, last);
return range(random_generator_);
}
private:
mt19937 random_generator_;
};
};
int main() {
Matrix<3, 5> a, b, c;
a.random_fill(10, 49);
b.random_fill(10, 49);
c = a + b;
a.show(4);
cout.put('\n');
b.show(4);
cout.put('\n');
c.show(4);
system("pause > nul");
}
Оператор + должен не модифицировать существующий объект, а создавать новый и возвращать его. При выполнении y=a+b переменная "a" не должна изменяться.