01/10/2018, 00:48

Gặp lỗi no matching function for call to ... khi nạp chồng toán tử + trong khi xây dựng lớp ma trận

#include <iostream>
#include <stdlib.h>
using namespace std;

class Matrix{
private:
    int rows, cols;
    int *element;
public:
    Matrix(int rows, int cols){
        this->rows = rows;
        this->cols = cols;
    }
    ~Matrix(){
        free(this->element);
        this->element = NULL;
    }
    Matrix operator+(const Matrix&);
   // friend istream& operator>>(istream&, Matrix&);
    //friend ostream& operator<<(ostream&, Matrix&);
};

Matrix Matrix::operator+(const Matrix& _Matrix){
    Matrix matrix;
    int size = this->rows*cols;
    matrix.element = (int *)malloc(sizeof(int)*size);
    for(int i=0; i<this->rows; i++){
        for(int j=0; j<this->cols; j++){
            matrix.element[i*this->cols+j] = this->element[i*this->cols+j] + _Matrix.element[i*this->cols+j];
        }
    }
    return matrix;
}
Bài liên quan
0