我有一个模板化的父类。
template <class T>
class Account
{
protected:
T balance;
int deposits;
int withdrawals;
T interestRate;
T serviceCharges;
bool status;
public:
...
有几个功能(一些是虚拟的,另一些则不是)。 然后我有一个继承的类(实际上是两个)下面是一个这样的类的例子。有一些错误即将出现,我似乎无法解决。
template <class T>
class Checking : public Account <T>
{
public:
void withdraw(double amt)
{
if (status == false)
{
cout << "Account is inactive.\n\n";
return;
}
try
{
if (amt < 0)
throw Account::NegativeAmount();
else if (balance - amt < 25 && balance - amt > 0)
{
cout << "\nYour account has fallen below $25.00.\n";
cout << "It will be deactivated.\n";
status = false;
}
else if (balance - amt < 0)
{
cout << "You are attempting to withdraw more than the ";
serviceCharges += 15.00;
cout << "account balance.\n";
}
else
Account::withdraw(amt); // base class function call
}
catch (Account::NegativeAmount())
{
cout << "Withdraw positive numbers only.\n";
}
}
};
我看到的另一个错误是此声明/代码行的错误:
code: throw Account::NegativeAmount();
error: 'template<class T> class Account' used without template parameters
如果我尝试通过添加
来修复它code: throw Account<T>::NegativeAmount();
仍有错误且未修复。