C++新手求助 1>savingaccount.obj : error LNK2001: 无法解析的外部符号 "private: static double Saving

#ifndefSAVINGACCOUNT_H#defineSAVINGACCOUNT_H#include<iostream>usingnamespacestd;class... #ifndef SAVINGACCOUNT_H
#define SAVINGACCOUNT_H
#include <iostream>
using namespace std;
class SavingAccount{
public:
SavingAccount(const double & value) : savingsBalance(value)
{
cout << "...." << endl;
}
double calculateMonthlyInterest()
{
double interestMonthly;
interestMonthly = savingsBalance * annualInterestRate / 12;
savingsBalance += interestMonthly;
return interestMonthly;
}
static void modifyInterestRate(double newValue)
{
annualInterestRate = newValue;
}
double getSavingsBalance()
{
return savingsBalance;
}
private:
double savingsBalance;
static double annualInterestRate;
};
#endif

#include <iostream>
#include <cstdlib>
#include "savingaccount.h"
using namespace std;
int main()
{
double interestRateMonthly;
SavingAccount saver1(2000),saver2(3000);
SavingAccount::modifyInterestRate(0.03);
interestRateMonthly = saver1.calculateMonthlyInterest() / 2000;
cout << "interestRateMonthly is : " << interestRateMonthly << endl;
saver2.calculateMonthlyInterest();
cout << "saver1 savingsBalance: " << saver1.getSavingsBalance() << endl;
cout << "saver2 savingsBalance: " << saver2.getSavingsBalance() << endl;
cout << interestRateMonthly << endl;
SavingAccount::modifyInterestRate(0.04);
cout << "saver1 next month interest : " << saver1.calculateMonthlyInterest() << endl;
cout << "saver2 next month interest : " << saver2.calculateMonthlyInterest() << endl;
cout << "saver1 new balance : " << saver1.getSavingsBalance() << endl;
cout << "saver2 new balance : " << saver2.getSavingsBalance() << endl;
system("pause");
return 0;
}

1>savingaccount.obj : error LNK2001: 无法解析的外部符号 "private: static double SavingAccount::annualInterestRate" (?annualInterestRate@SavingAccount@@0NA)
1>D:\我的文档\Visual Studio 2008\Projects\savingAccount\Debug\savingAccount.exe : fatal error LNK1120: 1 个无法解析的外部命令
展开
 我来答
chiconysun
推荐于2016-09-17 · TA获得超过2.2万个赞
知道大有可为答主
回答量:5410
采纳率:92%
帮助的人:2576万
展开全部
static double annualInterestRate;这个变量没有在头文件的后面显式初始化,写法为:
double SavingAccount::annualInterestRate = 0;
dl_会飞的青蛙
2013-04-19 · TA获得超过2456个赞
知道大有可为答主
回答量:3294
采纳率:0%
帮助的人:3376万
展开全部
不用c++ 所以不知道怎么回答
来自:求助得到的回答
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式