yeah.... can somebody take a quick look at the unfinished code below and let me know if i'm properly overloading the operators? thanks.
Code:
matrix matrix::operator + (matrix other) {
int y, x;
this->accesserror = false; other.accesserror = false;
if ((this->getrows() == other.getrows()) && (this->getcols() == other.getcols())) {
matrix temp(this->getrows(), this->getcols());
for (y = 1; y <= this->getrows(); y++) {
for (x = 1; x <= this->getcols(); x++) {
temp.setelem(y, x, (this->at(y, x) + other.at(y, x)));
if ((this->accesserror) || (other.accesserror) || (temp.accesserror)) { break; }
}
if ((this->accesserror) || (other.accesserror) || (temp.accesserror)) { break; }
}
} else {
matrix temp(1, 1);
temp.setelem(1, 1, 0);
this->accesserror = true; other.accesserror = true;
}
return temp;
} /*Matrix addition; make sure to check fail() */
and
Code:
bool matrix::operator == (matrix other) {
int y, x;
this->accesserror = false; other.accesserror = false;
/*Row and column check */
if (!((this->getrows() == other.getrows()) && (this->getcols() == other.getcols()))) {
return false;
}
else {
for (y = 1; y <= this->getrows(); y++) {
for (x = 1; x <= this->getcols(); x++) {
if ((this->at(y, x) != other.at(y, x)) {
return false;
}
}
}
}
}