Overloading Operator [][] c++ -


this question has answer here:

let there 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;              (int i=0;i<sizea;i++){                  (intj=0;j<sizeb;j++){                      tmpnew[i][j]=mymatrix[i][j]+b[i][j];                  }              }               return box;           } }; 

it working exept matrix operator+(const matrix& b) function

i want work co want create operator [][], possible?

i want example if see mat[i][j] return value in mat->mymatrix[i][j]

is possible?

is possible?

no, not without having intermediary row helper class provides overload operator[]().

the question if it's worth in preference of writing call operator overload:

t operator()(int,int) {     // ... } 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -