首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

一个小程序 LNK1120 LB=2001异常

2012-04-08 
一个小程序 LNK1120 LB2001错误#ifndef SAVINGACCOUNT_H#define SAVINGACCOUNT_Hclass SavingAccount{pub

一个小程序 LNK1120 LB=2001错误
#ifndef SAVINGACCOUNT_H
#define SAVINGACCOUNT_H

class SavingAccount
{

public:
SavingAccount(double = 0);
void calculateMonthlyInterest();
static void modifyInterestRate(int );
void print();
private:
double savingBalance;
static double annualInterestRate;
};

#endif

#include <iostream>
using namespace std;

#include "2.h"

SavingAccount::SavingAccount(double b)
:savingBalance(b)
{

}

void SavingAccount::calculateMonthlyInterest()
{
savingBalance = savingBalance * annualInterestRate/12;
}

void SavingAccount::modifyInterestRate(int a )
{
annualInterestRate = a;
}

void SavingAccount::print()
{
cout<<"The new savingsBalance is :"<<savingBalance;
}


#include <iostream>
using namespace std;

#include "2.h"

int main()
{
SavingAccount saver1(2000.00);
SavingAccount saver2(3000.00);
saver1.modifyInterestRate(0.03);
saver1.print();
saver2.print();
saver1.modifyInterestRate(0.04);
saver1.print();
saver2.print();
}


这个程序一运行就爆上面那两个错误 检查好多遍都不知道错在哪里 谁帮忙看下 谢谢了

[解决办法]
一个明显的错误时类中的方法modifyInterestRate(int)为整形,而作者在主函数中传入的确实浮点型。
[解决办法]
[img=http://]还有应该在类的实现文件中定义静态成员变量annualInterestRate,因为它不属于类的某一个对象

热点排行