I am getting undefined reference errors when I try to debug the following code.I tried simple test piece but still the same errors.First I thought it was c++ class creator but after than I wrote the Account.hpp and Account.cpp manualy still the same.How can I fix it.
Error Message:Terminal
main.cpp
#include <iostream>
#include "Account.hpp"
using namespace std;
int main()
{
Account erol_account;
erol_account.set_name("Erol's Account");
erol_account.set_balance(1000.0);
if (erol_account.deposit(200.0))
{
cout << "Deposit OK\n";
}
else
{
cout << "Deposit Not Allowed\n";
}
if (erol_account.withdraw(500.0))
{
cout << "Withdrawal OK\n";
}
else
{
cout << "No Sufficent Funds\n";
}
if (erol_account.withdraw(1500.0))
{
cout << "Withdrawal OK\n";
}
else
{
cout << "No Sufficent Funds\n";
}
return 0;
}
Account.hpp
#ifndef _ACCOUNT_H_
#define _ACCOUNT_H_
#include <string>
class Account
{
private:
// Attributes
std::string name;
double balance;
public:
// Methods
// Declared Inline
void set_balance(double bal) { balance = bal; }
double get_balance() { return balance; }
// Methods will declared outside the class decleration
void set_name(std::string n);
std::string get_name();
bool deposit(double amount);
bool withdraw(double amount);
};
#endif
Account.cpp
#include "Account.hpp"
void Account::set_name(std::string n)
{
name = n;
}
std::string Account::get_name()
{
return name;
}
bool Account::deposit(double amount)
{
// If very amount
balance += amount;
return true;
}
bool Account::withdraw(double amount)
{
if (balance - amount >= 0)
{
balance -= amount;
return true;
}
else
{
return false;
}
}