-2

Let there be a class :

template <class A_Type,int sizeA,int sizeB>
class Matrix {

    A_Type myMatrix[sizeA][sizeB];
    int sizeA_Val;
    int sizeB_Val;
public:
    Matrix();
    Matrix(A_Type val);

    int getSizeA()const{return sizeA_Val;} ;
    int getSizeB()const{return sizeB_Val;};

    A_Type mini() const;
    double avg() const;


    Matrix operator+(const Matrix& b)
          {
             Matrix<A_Type,sizeA,sizeB> tmpNew;
             for (int i=0;i<sizeA;i++){
                 for (intj=0;j<sizeB;j++){
                     tmpNew[i][j]=myMatrix[i][j]+b[i][j];
                 }
             }

             return box;
          }
};

it is working exept to the Matrix operator+(const Matrix& b) function

i want it to work co i want to create operator [][], is it possible?

i want for example if i see mat[i][j] it will return the value in the mat->myMatrix[i][j]

is it possible?

JohnnyF
  • 1,053
  • 4
  • 16
  • 31

1 Answers1

3

is it possible?

No, not without having an intermediary row helper class that also provides an overload for the operator[]().

The question is if it's worth it in preference of writing a call operator overload:

T operator()(int,int) {
    // ...
}
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190