fork(1) download
  1. class Matrix
  2. {
  3. private:
  4. std::vector<std::vector<T>> mat;
  5.  
  6. public:
  7. Matrix(){};
  8. ~Matrix(){};
  9.  
  10. Matrix(int rows, int collums){
  11. mat.resize(rows);
  12. for (auto &row : mat)
  13. row.resize(collums);
  14. }
  15. std::vector<T>& operator[] (unsigned int i) { return mat[i]; }
  16. const std::vector<T>& operator[] (unsigned int i) const { return mat[i]; }
  17. Matrix<T> operator*(const Matrix<T>& second) const {
  18. if (this->nCol() == second.nRows()){
  19. unsigned int nMax = this->nCol();
  20. Matrix<T> tmp(this->nRows(), second.nCol());
  21.  
  22. for (unsigned int r = 0; r < tmp.nRows(); ++r){
  23. for (unsigned int c = 0; c < tmp.nCol(); ++c){
  24. for (unsigned int n = 0; n < nMax; ++n){
  25. tmp[r][c] += this->operator[](r).at(n) * second[n].at(c);//<- я у мамы кодер.
  26. }
  27. }
  28.  
  29. }
  30. return tmp;
  31. }
  32. else
  33. return Matrix<T>(0, 0);
  34.  
  35. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:4:7: error: 'vector' in namespace 'std' does not name a template type
  std::vector<std::vector<T>> mat;
       ^
prog.cpp:15:7: error: 'vector' in namespace 'std' does not name a template type
  std::vector<T>& operator[] (unsigned int i) { return mat[i]; }
       ^
prog.cpp:16:13: error: 'vector' in namespace 'std' does not name a template type
  const std::vector<T>& operator[] (unsigned int i) const { return mat[i]; }
             ^
prog.cpp:17:2: error: 'Matrix' is not a template
  Matrix<T> operator*(const Matrix<T>& second) const {
  ^
prog.cpp:17:9: error: 'T' was not declared in this scope
  Matrix<T> operator*(const Matrix<T>& second) const {
         ^
prog.cpp:17:28: error: 'Matrix' is not a template
  Matrix<T> operator*(const Matrix<T>& second) const {
                            ^
prog.cpp:17:35: error: 'T' was not declared in this scope
  Matrix<T> operator*(const Matrix<T>& second) const {
                                   ^
prog.cpp:35:2: error: expected '}' at end of input
  }
  ^
prog.cpp: In constructor 'Matrix::Matrix(int, int)':
prog.cpp:11:3: error: 'mat' was not declared in this scope
   mat.resize(rows);
   ^
prog.cpp:12:20: error: unable to deduce 'auto&&' from 'mat'
   for (auto &row : mat)
                    ^
prog.cpp: In member function 'Matrix Matrix::operator*(const Matrix&) const':
prog.cpp:18:13: error: 'const class Matrix' has no member named 'nCol'
   if (this->nCol() == second.nRows()){
             ^
prog.cpp:18:30: error: 'const class Matrix' has no member named 'nRows'
   if (this->nCol() == second.nRows()){
                              ^
prog.cpp:19:30: error: 'const class Matrix' has no member named 'nCol'
    unsigned int nMax = this->nCol();
                              ^
prog.cpp:20:4: error: 'Matrix' is not a template
    Matrix<T> tmp(this->nRows(), second.nCol());
    ^
prog.cpp:20:11: error: 'T' was not declared in this scope
    Matrix<T> tmp(this->nRows(), second.nCol());
           ^
prog.cpp:20:24: error: 'const class Matrix' has no member named 'nRows'
    Matrix<T> tmp(this->nRows(), second.nCol());
                        ^
prog.cpp:20:40: error: 'const class Matrix' has no member named 'nCol'
    Matrix<T> tmp(this->nRows(), second.nCol());
                                        ^
prog.cpp:22:37: error: 'class Matrix' has no member named 'nRows'
    for (unsigned int r = 0; r < tmp.nRows(); ++r){
                                     ^
prog.cpp:23:38: error: 'class Matrix' has no member named 'nCol'
     for (unsigned int c = 0; c < tmp.nCol(); ++c){
                                      ^
prog.cpp:25:10: error: no match for 'operator[]' (operand types are 'Matrix' and 'unsigned int')
       tmp[r][c] += this->operator[](r).at(n) * second[n].at(c);//<- я у мамы кодер.
          ^
prog.cpp:25:35: error: 'const class Matrix' has no member named 'operator[]'
       tmp[r][c] += this->operator[](r).at(n) * second[n].at(c);//<- я у мамы кодер.
                                   ^
prog.cpp:25:54: error: no match for 'operator[]' (operand types are 'const Matrix' and 'unsigned int')
       tmp[r][c] += this->operator[](r).at(n) * second[n].at(c);//<- я у мамы кодер.
                                                      ^
prog.cpp:33:11: error: 'Matrix' is not a template
    return Matrix<T>(0, 0);
           ^
prog.cpp:33:18: error: 'T' was not declared in this scope
    return Matrix<T>(0, 0);
                  ^
prog.cpp: At global scope:
prog.cpp:35:2: error: expected unqualified-id at end of input
  }
  ^
stdout
Standard output is empty