title: Base Class and Derived Class private member variable usage
body: <p>I've developed a compiling bank system of different accounts. My base class is Account, and derived classes are Checking, Savings, MoneyMarket. The latter three inherit private member variable 'balance' from Account. All <strong>four</strong> accounts need to maintain and modify their own 'balance'. </p>
  
  <p>However, I'm confused about the relation between Account's balance and derived class's 'balance'. </p>
  
  <p>As you can see in Checking's getBalance(), it is forced to use Account's getBalance() due to the private variable, and the code only works when it displays Account::balance. This seems very strange, that it should call Account's balance to display it's own. </p>
  
  <p>Please note that that all of Account's public methods are virtual to allow override. </p>
  
  <p>Why does this work the way it is? Shouldn't the derived classes call their own copy of 'balance'?</p>
  
  <p>Note: this code works and correctly displays the exact modified balance for each object. 
  Below is Checking.cpp:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  #include "Checking.h"
  using namespace std;
  
  Checking::Checking() {setBalance(500); }
  
  Checking::~Checking() {setBalance(0);}
  
  void Checking::Withdrawal(double p_withdrawal){
      setBalance( getBalance(0) - p_withdrawal);
      cout &lt;&lt; setprecision(2) &lt;&lt; fixed;
      cout&lt;&lt;"\nWithdrawal from Checking leaves balance: "&lt;&lt;getBalance(0);
  }
  
  double Checking::getBalance(bool print){
      if (print==1)
          cout&lt;&lt;"\nBalance of Checking:"&lt;&lt; Account::getBalance(0);
      return Account::getBalance(1);
  }
  </code></pre>
  
  <p>And for Account.h:</p>
  
  <pre><code>#ifndef ACCOUNT_H
  #define ACCOUNT_H
  using namespace std;
  
  class Account{
  public:
      Account();
      ~Account();
  
      virtual double getBalance(bool);
      virtual void setBalance(double);
  
      virtual void Deposit(double);
      virtual void Withdrawal(double);
  
      virtual void Transfer(Account&amp;, Account&amp;, double); 
  
  private:
      double balance;
  
  };
  
  #endif 
  </code></pre>