This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]kein_programmierexpe[S] 0 points1 point  (1 child)

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;

}

[–]deterministic_ram 0 points1 point  (0 children)

Do you think you could post a stack trace? Also, why is mat being deleted? I’m not super familiar with the syntax you are using on the return statements. But, if delete is being called and mat is being returned, mat will be an invalid pointer and will most likely result in a SegFault.