Pregunta

Estoy tratando de hacer otro ejercicio del libro de Deitel. El programa calcula el interés mensual e imprime los nuevos saldos para cada uno de los ahorradores. A medida que el ejercicio es parte del capítulo relacionado con la memoria dinámica, estoy usando "nuevas" operadores y "eliminar". Por alguna razón, me sale estos dos errores:

  

LNK2019: símbolo externo sin resolver WinMain @ 16 referencia en función ___ tmainCRTStartup

     

LNK1120 error fatal: 1 externos sin resolver

Este es el archivo de encabezado de clase.

//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 archivo con definiciones de funciones miembro

//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 finalmente programa controlador:

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

He pasado una hora tratando de resolver esto sin éxito.

¿Fue útil?

Solución

Vaya a "ajustes Linker -> Sistema". Cambie el campo "Subsistema" de "Windows" a "consola".

Otros consejos

Parece que está escribiendo una aplicación de consola estándar (que tiene int main()), pero que el enlazador está a la espera de encontrar un punto de entrada WinMain ventanas.

En las páginas de propiedades del proyecto yout, en la sección Linker, la opción del sistema / subsistema, ¿tiene "Windows (/ SUBSISTEMA: WINDOWS)" seleccionado? Si es así, pruebe a cambiar a "Consola (/ SUBSISTEMA: consola)"

Al crear un nuevo proyecto, seleccione "Aplicación de consola Win32" en lugar de "Proyecto Win32".

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top