#include <iostream>
#include <vector>
#include <assert.h>
class Matrix{
private:
int row;
int col;
std::vector<std::vector<int>> data;
public:
Matrix() = default;
Matrix(int row, int col): row(row), col(col), data(row , std::vector<int>(col, 0)){};
Matrix(std::vector<std::vector<int>> elements){
this->row = elements.size();
this->col = elements[0].size();
this->data = elements;
};
/**
*
*/
// std::ostream& operator<<(std::ostream& os){
// os << this->row << " -- " << this->col << std::endl;
// return os;
// };
std::vector<int>& operator[](int index){
return this->data[index];
};
Matrix operator*(Matrix& b){
assert(this->col == b.row);
Matrix c(this->row, this->col);
for(int i = 0; i < this->row; i++){
for(int j = 0; j < this->col; j++){
for(int k = 0; k < this->col; k++){
c[i][j] += this->data[i][k] * b[k][j];
}
}
}
return c;
};
void show(){
for(int i = 0; i < this->row; i++){
std::cout << "[";
for(int j = 0; j < this->col; j++){
std::cout << this->data[i][j] << " ";
}
std::cout << "]" << std::endl;
}
}
};
// std::ostream& operator<<(std::ostream os, )
int main(){
Matrix a({{1,0,0}, {0,1,0}, {0,0,1}});
Matrix b({{1,2,3}, {1,1,1}, {0,0,1}});
// std::cout << a; // 类内部重载 << 时这个写法错误
// a << std::cout; // 类内部重载 << 时只能这么写,反常规
Matrix c = a * b;
c.show();
// [1 2 3 ]
// [1 1 1 ]
// [0 0 1 ]
return 0;
}