operator const trouble

I am working with code from a book. I am getting errors in vim and xcode from a direct copy of the code.

const Money operator +(const Money& amount1, const Money& amount 2);
const Money operator -(const Money& amount1, const Money& amount 2);
bool operator ==(const Money& amount1, const Money& amount 2);
const Money operator -(const Money& amount);

errors want me to add a comma or parenthesis. Anyone know what the issue might be?
Thanks.
First, the obvious question is this - is Money actually defined anywhere in your code? And did you forget a closing semicolon or parenthesis further up where you have the code? Apart from that, its not often that you want to pass by const value - normal pass by value is perfectly good for most situations.
This is what I have...I am trying to learn const value. I seem to not be missing anything.

#include <iostream>
#include <cstdlib>
#include <cmath>

using namespace std;

class Money
{
public:
Money();
Money(double amount);
Money(int theDollars, int theCents);
Money(int theDollars);
double getAmount() const;
int getDollars() const;
int getCents() const;
void input();
void output();

private:
int dollars;
int cents;
int dollarsPart(double amount) const;
int centsPart(double amount) const;
int round(double number) const;
};


const Money operator +(const Money& amount1, const Money& amount 2);//error, seems to not like the addition of const Money& amount 2
const Money operator -(const Money& amount1, const Money& amount 2);//error
bool operator ==(const Money& amount1, const Money& amount 2);//error
const Money operator -(const Money& amount); //This line returns no error
Aah, I worked it out: This is why you need to show us your code in code tags! You have a space between the 'operator' and the '+' - they need to be concantenated, otherwise you are trying to... I don't know... do something else. So it should be like this:
1
2
3
const Money operator+ (/*...*/);
// NOT
const Money operator + (/*...*/);
Last edited on
Topic archived. No new replies allowed.