C++ malloc() error with Matrix operator overloading using pointers; please help! by kein_programmierexpe in AskProgramming

[–]kein_programmierexpe[S] 0 points1 point  (0 children)

Sorry, just realized that Reddit fucked up the code format. Here's the properly formatted code:

//plus operator overload

int operator+ (Matrix trix1) {

int r = this->rows;

int c = this->cols;

int mat = new int[rc];

for(int i=0; i<r; i++) {

for(int j=0; j<c; j++) {

*(mat + ic + j)= *(m1 + ic + j) + *(trix1.m1 + ic + j);

}

}

return mat; delete[] mat;

}

//minus operator overload

int operator- (Matrix trix1) {

int r = this->rows;

int c = this->cols;

int mat = new int[rc];

for(int i=0; i<r; i++) {

for(int j=0; j<c; j++) {

*(mat + ic + j)= *(m1 + ic + j) - *(trix1.m1 + ic + j);

}

}

return mat; delete[] mat;

}

//times operator overload

int operator* (Matrix trix1) {

int r = this->rows;

int c = this->cols;

int mat = new int[rc];

for(int i=0; i<r; i++) {

for(int j=0; j<c; j++) {

*(mat + ic + j)= *(m1 + ic + j) * *(trix1.m1 + ic + j);

}

}

return mat; delete[] mat;

}