Overloading Operator [][] c++ -
this question has answer here:
- operator[][] overload 15 answers
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
Post a Comment