invalid conversion from ‘Rational*’ to ‘int’

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)’

Where do I convert anything to an int? :\

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*

 * 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;
  } 
Try changing this -> Rational final = new Rational(nfinal, dfinal);

to this -> Rational final(nfinal, dfinal);
Topic archived. No new replies allowed.