title: Unresolved external symbol error in c++
body: <p>I am trying to do a simple hw problem involving namespace, static data members and functions.  I am getting an unresolved external symbol error </p>
  
  <pre><code>Error   1   error LNK2001: unresolved external symbol "private: static double JWong::SavingsAccount::annualInterestRate" (?annualInterestRate@SavingsAccount@JWong@@0NA)    SavingsAccount.obj  SavingsAccount
  </code></pre>
  
  <p>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:</p>
  
  <p>SavingsAccount.h file</p>
  
  <pre><code>#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
  </code></pre>
  
  <p>SavingsAccount.cpp file</p>
  
  <pre><code>#include &lt;iostream&gt;
  #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-&gt;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;
  }
  </code></pre>