i overloaded the operator '-' to subtract 2 Distances. i dont want to accept negative distance so how do i exit the function? i tried "return -1;" but the return type is of type Distance. do i have to do the error checking in main?
Code:Distance Distance::operator - (Distance d2) const //return difference { int f = feet - d2.feet; //subtract feet float i = inches - d2.inches; //subtract inches if(i < 0) { --f; i = 12 - (i * -1); } if(f < 0) { cout << "Error: Negative Distance." << endl; //this line doesnt print for some reason return Distance(0,0.0); } else return Distance(f,i); }