I am trying to do a simple hw problem involving namespace, static data members and functions. I am getting an unresolved external symbol error
Error 1 error LNK2001: unresolved external symbol "private: static double JWong::SavingsAccount::annualInterestRate" (?annualInterestRate@SavingsAccount@JWong@@0NA) SavingsAccount.obj SavingsAccount
And I don't see why I am getting this error. Maybe I don't know something about static variables compared to regular data members that is causing this error. Here is my code:
SavingsAccount.h file
#ifndef JWONG_SAVINGSACCOUNT_H
#define JWONG_SAVINGSACCOUNT_H
namespace JWong
{
class SavingsAccount
{
public:
// default constructor
SavingsAccount();
// constructor
SavingsAccount(double savingsBalance);
double getSavingsBalance();
void setSavingsBalance(double savingsBalance);
double calculateMonthlyInterest();
// static functions
static void modifyInterestRate(double newInterestRate);
static double getAnnualInterestRest();
private:
double savingsBalance;
// static members
static double annualInterestRate;
};
}
#endif
SavingsAccount.cpp file
#include <iostream>
#include "SavingsAccount.h"
// default constructor, set savingsBalance to 0
JWong::SavingsAccount::SavingsAccount() : savingsBalance(0)
{}
// constructor
JWong::SavingsAccount::SavingsAccount(double savingsBalance) : savingsBalance(savingsBalance)
{}
double JWong::SavingsAccount::getSavingsBalance()
{
return savingsBalance;
}
void JWong::SavingsAccount::setSavingsBalance(double savingsBalance)
{
this->savingsBalance = savingsBalance;
}
// returns monthly interest and sets savingsBalance to new amount
double JWong::SavingsAccount::calculateMonthlyInterest()
{
double monthlyInterest = savingsBalance * SavingsAccount::annualInterestRate / 12;
setSavingsBalance(savingsBalance + monthlyInterest);
return monthlyInterest;
}
void JWong::SavingsAccount::modifyInterestRate(double newInterestRate)
{
SavingsAccount::annualInterestRate = newInterestRate;
}
double JWong::SavingsAccount::getAnnualInterestRest()
{
return SavingsAccount::annualInterestRate;
}