J'essaie de faire un autre exercice à partir du livre de Deitel. Le programme calcule l'intérêt mensuel et imprime les nouveaux soldes pour chacun des épargnants. Comme l'exercice fait partie du chapitre relatif à la mémoire dynamique, j'utilise les opérateurs "nouveaux" et "supprimer". Pour une raison quelconque, je reçois ces deux erreurs:Erreurs C++ LNK1120 et LNK2019: "symbole externe non résolu WinMain @ 16"
LNK2019: symbole externe non résolu WinMain @ 16 référencé dans la fonction ___tmainCRTStartup
LNK1120 erreur fatale: 1 externals non résolues
Voici le fichier d'en-tête de classe .
//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;
};
fichier Cpp avec fonction membre définitions
//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
Fin enfin programme pilote:
#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;
}
J'ai passé une heure à essayer de comprendre cela avec Sans succès.
C'était tout. Merci!!! – Mike55