我正试图从Deitel的书中做另一个练习.该程序计算每月利息并打印每个储户的新余额.由于练习是与动态内存相关的章节的一部分,我使用的是"new"和"delete"运算符.出于某种原因,我得到了这两个错误:
LNK2019:函数___tmainCRTStartup中引用的未解析的外部符号WinMain @ 16
致命错误LNK1120:1个未解析的外部因素
这是类头文件.
//SavingsAccount.h
//Header file for class SavingsAccount
class SavingsAccount
{
public:
static double annualInterestRate;
SavingsAccount(double amount=0);//default constructor intialize
//to 0 if no argument
double getBalance() const;//returns pointer to current balance
double calculateMonthlyInterest();
static void modifyInterestRate(double interestRate):
~SavingsAccount();//destructor
private:
double *savingsBalance;
};
Run Code Online (Sandbox Code Playgroud)
具有成员函数定义的Cpp文件
//SavingsAccount class defintion
#include "SavingsAccount.h"
double SavingsAccount::annualInterestRate=0;//define and intialize static data
//member at file scope
SavingsAccount::SavingsAccount(double amount)
:savingsBalance(new double(amount))//intialize savingsBalance to point to new object
{//empty body
}//end of constructor
double SavingsAccount::getBalance()const
{ …Run Code Online (Sandbox Code Playgroud)