2009-08-09 12 views
5

Próbuję wykonać kolejne ćwiczenie z książki Deitela. Program oblicza miesięczne odsetki i drukuje nowe salda dla każdego z oszczędzających. Ponieważ ćwiczenie jest częścią rozdziału dotyczącego pamięci dynamicznej, używam operatorów "nowy" i "usuń". Z jakiegoś powodu, mam te dwa błędy:Błędy C++ LNK1120 i LNK2019: "nierozwiązany symbol zewnętrzny WinMain @ 16"

LNK2019: nierozwiązanych zewnętrznych symbolu WinMain @ 16 odwołuje się funkcja ___tmainCRTStartup

błąd krytyczny LNK1120: 1 nierozwiązane externals

Oto plik klasy nagłówek .

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

pliku cpp z funkcji członka

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

Koniec wreszcie Program kierowca:

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

spędziłem godziny próbuje dowiedzieć się tego z bez powodzenia.

Odpowiedz

7

Przejdź do "Ustawienia łącznika -> System". Zmień pole "Podsystem" z "Windows" na "Konsola".

+0

To wszystko. Dzięki!!! – Mike55

2

Podczas tworzenia nowego projektu wybierz "Win32 Console Application" zamiast "Win32 Project".

3

Wygląda na to, że piszesz standardową aplikację konsolową (masz int main()), ale linker spodziewa się znaleźć punkt wejścia do systemu Windows WinMain.

Na stronach właściwości projektu yout, w sekcji Łącznik, opcja System/Podsystem, czy wybrano opcję "Windows (/ SUBSYSTEM: WINDOWS)"? Jeśli tak, spróbuj zmienić ją na "Console (/ SUBSYSTEM: CONSOLE)"

Powiązane problemy