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 个无法解析的外部命令 展开
#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 个无法解析的外部命令 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询