c++ - Template parameter as parameter of other template -


i've got matrix class. it's template type, rows , cols static allocation of small matrix. problem overload of operator* , operator*=. in case operation must granted different object: same type, rows equals column , number of columns. wrote code , works, wonder if can force use same type t instead of having type t1. same thing rows , columns.

template<typename t, int r, int c> class matrix {  private:    //some data.....  public:    //some methods.....   template <typename t1, int r1, int c1> <----here i'd use t type   matrix<t,r,c1> operator*(const matrix<t,r1,c1>& rhs);   template <typename t1, int r1, int c1>   matrix<t,r,c1>& operator*=(const matrix<t,r1,c1>& rhs); } 

for operator *, template parameters don't have match function arguments, can leave out. also, there restriction number of rows of second matrix match number of columns of first matrix, need 1 template parameter:

template<typename t, int r, int c> class matrix {  private:    //some data.....  public:    //some methods.....   template <int c1>   matrix<t,r,c1> operator*(const matrix<t,c,c1>& rhs) const; }; 

operator *= can work square matrices, have careful there.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -