Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename T>
- Matrix<T>& Matrix<T>::operator=(Matrix<T>& rhs){
- assert(this->n_row == rhs.n_row);
- assert(this->n_col == rhs.n_col);
- int offset;
- for(int i=0; i<this->n_row; i++){
- offset = i * n_col;
- for(int j =0; j<this->n_col; j++){
- this->data[offset+j] = rhs.data[offset+j];
- }
- }
- return *this;
- }
- template<typename T>
- Matrix<T>& Matrix<T>::operator*=(const T scalar){
- int offset;
- for(int i=0; i<this->n_row; i++){
- offset = i * this->n_col;
- for(int j=0; j<this->n_col; j++){
- this->data[offset+j] *= scalar;
- }
- }
- return *this;
- }
- template<typename T>
- Matrix<T> Matrix<T>::operator*(const T scalar){
- Matrix<T> lhs(*this);
- lhs *= scalar;
- return lhs;
- }
Add Comment
Please, Sign In to add comment