C ++ LNK1120和LNK2019错误:“未解析的外部符号WinMain @ 16"; [英] C++ LNK1120 and LNK2019 errors: "unresolved external symbol WinMain@16"

查看:167
本文介绍了C ++ LNK1120和LNK2019错误:“未解析的外部符号WinMain @ 16";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Deitel的书中进行另一项练习.该程序计算每月利息,并为每个储蓄者打印新的余额.由于本练习是与动态内存相关的章节的一部分,因此我将使用"new"和"delete"运算符.由于某些原因,我会遇到以下两个错误:

I'm trying to do another exercise from Deitel's book. The program calculates the monthly interest and prints the new balances for each of the savers. As the exercise is part of the chapter related to dynamic memory, I'm using "new" and "delete" operators. For some reason, I get these two errors:

LNK2019:函数___tmainCRTStartup中引用的未解析的外部符号WinMain @ 16

LNK2019: unresolved external symbol WinMain@16 referenced in function ___tmainCRTStartup

致命错误LNK1120:1个未解决的外部因素

fatal error LNK1120: 1 unresolved externals

这是类头文件.

//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;
};

具有成员函数定义的Cpp文件

Cpp file with member function definitions

//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
{
    return *savingsBalance;
}

double SavingsAccount::calculateMonthlyInterest()
{
    double monthlyInterest=((*savingsBalance)*annualInterestRate)/12;

    *savingsBalance=*savingsBalance+monthlyInterest;

    return monthlyInterest;
}

void SavingsAccount::modifyInterestRate(double interestRate)
{
    annualInterestRate=interestRate;
}

SavingsAccount::~SavingsAccount()
{
    delete savingsBalance;
}//end of destructor

最终结束驱动程序:

End finally driver program :

#include <iostream>
#include "SavingsAccount.h"

using namespace std;

int main()
{
SavingsAccount saver1(2000.0);
SavingsAccount saver2(3000.0);

SavingsAccount::modifyInterestRate(0.03);//set interest rate to 3%

cout<<"Saver1 monthly interest: "<<saver1.calculateMonthlyInterest()<<endl;
cout<<"Saver2 monthly interest: "<<saver2.calculateMonthlyInterest()<<endl;

cout<<"Saver1 balance: "<<saver2.getBalance()<<endl;
cout<<"Saver1 balance: "<<saver2.getBalance()<<endl;

return 0;
}

我花了一个小时试图解决这个问题,但没有成功.

I have spent an hour trying to figure this out with no success.

推荐答案

转到链接器设置->系统".将字段子系统"从"Windows"更改为控制台".

Go to "Linker settings -> System". Change the field "Subsystem" from "Windows" to "Console".

这篇关于C ++ LNK1120和LNK2019错误:“未解析的外部符号WinMain @ 16";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆