Operator Overloading

  • + 0 comments

    Hello i want to share my solution, enjoy:

    class Matrix {
    public:
        vector<vector<int>> a;
    
        Matrix operator+(const Matrix& b) {
        Matrix m;
        m.a.resize(b.a.size());
            for (int i = 0; i < a.size(); i++) {
                m.a[i].resize(b.a[i].size());
            }
    
        for (int i = 0; i < b.a.size(); i++) {
            for (int j = 0; j < b.a[i].size(); j++) {
                m.a[i][j] = a[i][j] + b.a[i][j];
            }
        }
        return m;
    }
    };