class help

closed account (i8bjz8AR)
Can't figure out how to fix this, any help appreciated! Getting the error
 
expected unqualified-id before ‘public
I tried commenting out void reduce(); and recompiling and gave me the same error

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Rational
{
private:
//the numerator and denominator
void reduce();
 int num, den;
};

void reduce();

public:
  //accessors
  int get_numerator() { return num; }
  int get_denominator() { return den; }
  int num, den;
Last edited on
why are your stuff outside the class?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Rational
{
private:
	//the numerator and denominator
	void reduce();
	int num, den;

public:
	//accessors
	int get_numerator() { return num; }
	int get_denominator() { return den; }
	int num, den;
};

void reduce(); 


Im not sure why you have 2 functions named reduce and one of them is outside the class.
And Im not sure why you're creating int num, den; twice
Last edited on
closed account (i8bjz8AR)
oh wow, haha thank you both! Also another question, i think this is just a warning but how do i get rid of this?

1
2
test.hpp:77:27: warning: inheriting constructors only available with -std=c++11 or -std=gnu++11 [enabled by default]
   using std::logic_error::logic_error;
Well. In this code there is no sign of constructor inheritence so Im guessing you got code you're not showing us. Either way, read this -
http://stackoverflow.com/questions/347358/inheriting-constructors

And perhaps upgrade to modern c++11.
closed account (i8bjz8AR)
correct, I went to that file and here is that code from line 77.. I didn't write this, it was starting code that we were given.

1
2
3
4
5
6
7
8
9
10
11
// -------------------------------------------------------------------------- //
// Error handling utilities

namespace uacs
{

// Represents a failure due to a logic error.
struct Assertion : std::logic_error
{
  using std::logic_error::logic_error;
};
Hi,

Do you have -std+c++11 or -std=c++14 when you compile ? Your compiler probably has the capability, just it's not being enabled.
Topic archived. No new replies allowed.