Program crash when creating object
Apr 3, 2017 at 4:33pm UTC
Hello everyone!
I've got a strange problem with the following class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
//header file
#ifndef ECONOMY_H
#define ECONOMY_H
#include <iostream>
enum PaymentError
{
ERR_NOT_ENOUGH_FUNDS,
ERR_PAYMENT_SUCCESS
};
class Economy
{
private :
long long m_money;
public :
Economy(long long startingMoney);
PaymentError Pay(long long amount);
void Receive(long long amount);
void PrintBalance();
long long getBalance();
};
#endif
//source file
#include "Economy.h"
Economy::Economy(long long startingMoney) : m_money(startingMoney) { }
PaymentError Economy::Pay(long long amount)
{
if (m_money >= amount)
{
m_money -= amount;
return ERR_PAYMENT_SUCCESS;
}
else return ERR_NOT_ENOUGH_FUNDS;
}
void Economy::Receive(long long amount)
{
m_money += amount;
}
void Economy::PrintBalance()
{
std::cout << "You currently have: $" << m_money << "\n" ;
}
long long Economy::getBalance() { return m_money; }
This used to work but now it doesn't anymore. Here is the line where I create my
object:
*m_eco = new Economy(12000);
Any help would be appreciated.
Last edited on Apr 3, 2017 at 4:35pm UTC
Apr 3, 2017 at 4:38pm UTC
Oh well, I found it. I passed in a const long long argument into the function that creates the object. This function uses that argument to create the object. Stupid me :)
Topic archived. No new replies allowed.