C++ 缺少模板参数错误

C++ 缺少模板参数错误,c++,templates,arguments,C++,Templates,Arguments,我有以下代码: #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(){};

我有以下代码:

#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   
构造函数和方法setValue的实现为:

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;
}
我得到了一个错误:

error: expected primary-expression before ‘(’ token
我可以创建空的货币对象(无错误),如:

但是当我调用方法setValue时:

cur.setValue(minus, 2, 25);
错误再次出现:

error: missing template arguments before ‘,’ token

有什么建议/想法吗?

如果我没弄错的话,您使用的代码示例不在currency类中。如果是这样,枚举值“减”就没有定义(或者可能是由除您之外的其他人定义)。要实际引用您的signType枚举,您必须使用正确的作用域,即:

cur.setValue(currency::minus, 2, 25);
编辑:与构造函数相同:

currency(currency::minus, 2, 25);

当然,在类内部,您可以只引用减号。

如果我没有弄错的话,您使用的代码示例不在currency类中。如果是这样,枚举值“减”就没有定义(或者可能是由除您之外的其他人定义)。要实际引用您的signType枚举,您必须使用正确的作用域,即:

cur.setValue(currency::minus, 2, 25);
编辑:与构造函数相同:

currency(currency::minus, 2, 25);

当然,在课堂上,你可以只参考减号。

试试
货币::减号


您在任何地方都有使用命名空间std的
吗?里面有一个
std::minus

试试
currency::minus


您在任何地方都有使用命名空间std的
吗?其中有一个
std::减号

符号名称重叠。编译器认为需要的
减号是。您想使用
currency::minus
,因此必须明确要求:

currency cur = currency(currency::minus, 2, 25);

您有重叠的符号名称。编译器认为需要的
减号是。您想使用
currency::minus
,因此必须明确要求:

currency cur = currency(currency::minus, 2, 25);

请发布一个最小的、完整的程序来演示错误。(您的程序既不是最小的,也不是完整的。)在创建最小的、完整的示例时,您自己可能会发现错误。请参阅。请发布一个演示错误的最小完整程序。(您的程序既不是最小的,也不是完整的。)在创建最小的、完整的示例时,您自己可能会发现错误。这是一个很好的例子,说明了为什么我们从来没有,从来没有,从来没有,说
使用名称空间std与其说我是
使用名称空间std的支持者,不如说我是never的反对者。只要你知道自己在做什么,就不应该有任何顾虑。也就是说,不要使用命名空间std做
;-)这是一个很好的例子,说明了为什么我们从来没有,从来没有,从来没有,说
使用名称空间std与其说我是
使用名称空间std的支持者,不如说我是never的反对者。只要你知道自己在做什么,就不应该有任何顾虑。也就是说,不要使用命名空间std做
;-)