c++ - '=' AND '!=' operator overloading problem -
okay, evil compiler keeps rejecting '=' , '!=' overloaded operators (i think) both polynomial , rational classes. appreciated.
using namespace std; class polynomial { public: //constructor polynomial() { ( int = 0; < 100; i++ ) { coefficient[i] = 0; } } ~polynomial(){} void polynomialset ( rational , int b ) //polynomialsetter function { coefficient[b] = a; exponent = b; } . . . . const polynomial &polynomial::operator=(const polynomial &a) { if (&a == this) return *this; } bool polynomial::operator!=(polynomial &a) { return !(*this == a); } *************************************************************************** using namespace std; class rational { public: //constructors rational (int a, int b) { //rational( const int &a, const int &b){ if (a != 0) { if (b != 0) { this->numerator = a; this->denominator = b; } } } rational(){} ~rational() {} . . . . bool rational::operator!=(rational a) { return (a.numerator != numerator) && (a.denominator != denominator); } rational rational::operator =(const rational &a) { this->numerator = a.numerator; this->denominator = a.denominator; return *this; }
here 3 error messages:
polynomial.h(35) : error c2679: binary '=' : no operator found takes right-hand operand of type 'int' (or there no acceptable conversion) rational.h(99): 'rational rational::operator =(const rational &)' while trying match argument list '(rational, int)' polynomial.h(53) : error c2679: binary '!=' : no operator found takes right-hand operand of type 'int' (or there no acceptable conversion) rational.h(94): 'bool rational::operator !=(rational)' while trying match argument list '(rational, int)' polynomial.h(63) : error c2679: binary '!=' : no operator found takes right-hand operand of type 'int' (or there no acceptable conversion) rational.h(94): 'bool rational::operator !=(rational)' while trying match argument list '(rational, int)' ========== build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
help???
try reading error messages?
binary '=' .... right-hand operand of type 'int' .... while trying match argument list '(rational, int)'
both operator = implementations can see take rational&
or polynomial&
none take int. being said there information missing question.
binary '!=' .... right-hand operand of type 'int' .... hile trying match argument list '(rational, int)'
same problem.
all aside, operator =
assignment operator... operator ==
boolean equality. can see of code looks have 2 mixed up. fixing alone set on way solution.
Comments
Post a Comment