I am writing a kind of matrix-library, so I gave my matrix a operator +
, using operator overloading. It looks something like this.
friend matrix<T, size_x, size_y> operator + (const matrix<T, size_x, size_y> & Input_1, const matrix<T, size_x, size_y> & Input_2){
matrix<T, size_x, size_y> Output;
for (int i=0; i<size_x; i++){
for (int j=0; j<size_y; j++){
Output.value[i][j]=Input_1.value[i][j]+Input_2.value[i][j];
}
}
return Output;
}
As far, as I tested it, it works. Now I like to add the -, /, * operators too, they all work the same. Of course I can use copy, replace and paste. But this is bad for readability and maintainability. Is there a smarter solution and perhaps a concept, since I don't know the name of the concept to google it? I just found, how to overload a single operator.