C ++ LNK1120とLNK2019エラー:「未解決の外部シンボルのWinMain @ 16」
-
12-09-2019 - |
質問
私はDeitelの本から別の運動をやろうとしています。プログラムは、毎月の利息を計算し、貯蓄ごとに新しい残高を出力します。演習では、動的メモリに関連する章の一部であるとして、私は「新」と「削除」の演算子を使用しています。何らかの理由で、私はこれらの2つのエラーを取得します:
LNK2019:関数で参照16 @未解決の外部シンボルのWinMain ___ tmainCRTStartup
致命的なエラー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;
};
メンバ関数定義を持つ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
{
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
エンド最後にドライバプログラム:
#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;
}
私は成功しませんこれを理解しようとしている時間を費やしています。
解決
に移動し、 "リンカの設定 - >システム"。 「コンソール」への「Windows」からフィールド「サブシステム」を変更します。
他のヒント
あなたは(あなたが
int main()
を持っている)標準のコンソールアプリケーションを作成しているが、リンカは、WindowsのエントリポイントWinMain
を見つけることが期待されていることのようにに見えます。
youtは、プロジェクトのプロパティページでは、リンカー部分、システム/サブシステムオプション、あなたが持っている中での "Windows(/ SUBSYSTEM:WINDOWS)" を選択?その場合は、変更してみてくださいそれを "コンソール(/ SUBSYSTEM:CONSOLE)"
新しいプロジェクトを作成する場合は、代わりに「Win32プロジェクト」の「Win32コンソールアプリケーション」を選択します。
所属していません StackOverflow