I'm pretty new to C++ and I am working with classes, and I'm not sure why I'm receiving this error. I'm not finished, but I want in my Rational plus funtion to be able to add the numerator and denominators together and then return a Rational with the added values. My header file specifies a private for the values "num" and "denom".
However, I keep getting this when I try to compile it:
rational.cpp:48: error: invalid conversion from ‘Rational*’ to ‘int’
rational.cpp:48: error: initializing argument 1 of ‘Rational::Rational(int)’
/*
* Implementation of rational number type
* CSE 374 HW7, Sp10
*/
#include "rational.h"
// constructors:
// Construct Rational 0/1
Rational::Rational(){
num = 0;
denom = 1;
}
// Construct Rational n/1
Rational::Rational(int n) {
num = n;
denom = 1;
}
// Construct Rational n/d
Rational::Rational(int n, int d) {
num = n;
denom = d;
}
// accessors: return the numerator and denominator of this Rational.
// Results are in lowest terms (i.e., for rational r, r.n() and r.d()
// have no common integer divisors greater than 1).
int Rational::n(){
return num;
}
int Rational::d() {
return denom;
}
// arithmetic: return a new Rational that results from combining
// this Rational with another. Neither operand is changed.
// = this + other
Rational Rational::plus(Rational other) {
int nfinal;
int dfinal;
nfinal = num + other.n();
dfinal = denom + other.d();
Rational final = new Rational(nfinal, dfinal);
return final;
}