Reputation: 413
I have the following code:
#ifndef CURRENCY_H_
#define CURRENCY_H_
class currency
{
public:
enum signType {plus, minus};
currency(signType theSign = plus, unsigned long theDollars = 0, unsigned int theCents = 0);
~currency(){};
void setValue(signType, unsigned long, unsigned int);
void setValue(double);
signType getSign() const {return sign;};
unsigned long getDollars() const {return dollars;};
unsigned int getCents() const {return cents;};
currency add(const currency&) const;
currency& increment(const currency&);
void output() const;
private:
signType sign;
unsigned long dollars;
unsigned int cents;
};
#endif
The implementation of the constructor and the method setValue is:
currency::currency(signType theSign, unsigned long theDollars, unsigned int theCents)
{
setValue(theSign, theDollars, theCents);
}
void currency::setValue(signType theSign, unsigned long theDollars, unsigned int theCents)
{
if(theCents > 99)
throw invalid_argument("Cents should be < 100");
this.sign = theSign;
dollars = theDollars;
cents = theCents;
}
When I try to create a currency object like:
currency cur = currency(minus, 2, 25);
I got the error:
error: expected primary-expression before ‘(’ token
I can create an empty currency object (no errors) like:
currency cur;
but when I call the method setValue:
cur.setValue(minus, 2, 25);
the error appears again:
error: missing template arguments before ‘,’ token
Any advice/idea?
Upvotes: 1
Views: 2554
Reputation: 8644
You've got overlapping symbol names. The minus
your compiler thinks you want is std::minus<T>
. You want to use currency::minus
, so you have to ask for it explicitly:
currency cur = currency(currency::minus, 2, 25);
Upvotes: 3
Reputation: 143299
Try currency::minus
.
Do you have using namespace std
anywhere? There's an std::minus
in it.
Upvotes: 2
Reputation: 195
If I'm not mistaken, you are using your code examples outside of the currency class. If so, the enum value "minus" is not defined (or propably by something other but you). To actually refer to your signType enum you have to use the correct scope, i.e.:
cur.setValue(currency::minus, 2, 25);
edit: the same for the constructor:
currency(currency::minus, 2, 25);
Inside of the class you are of course allowed to just refer to minus.
Upvotes: 2