title: Override member field in derived classes
body: <p>I have a code snippet below:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  class Base {
  public:
      Base() : b(0) {}
      int get();
      virtual void sayhello() { cout &lt;&lt; "Hello from Base with b: " &lt;&lt; b &lt;&lt; endl; }
  private:
      int b;
  };
  
  int Base::get() {sayhello(); return b;} 
  
  class Derived : public Base {
  public:
      Derived(double b_):b(b_){}
      void sayhello() { cout &lt;&lt; "Hello from Derived with b: " &lt;&lt; b &lt;&lt; endl; }
  private:
      double b;
  };
  
  int main() {
      Derived d(10.0);
      Base b = d;
  
      cout &lt;&lt; "Derived b: " &lt;&lt; d.get() &lt;&lt; endl;
      cout &lt;&lt; "Base b: " &lt;&lt; b.get() &lt;&lt; endl;
  }
  </code></pre>
  
  <p>Run the compiled executable and I find the result is out of my expectation on my <strong>llvm-g++ 4.2</strong> machine. The output on my box is as</p>
  
  <pre><code>Hello from Derived with b: 10
  Derived b: 0
  Hello from Base with b: 0
  Base b: 0
  </code></pre>
  
  <p>What I want to do in the code is to override a member field (<code>b</code>) in <code>Derived</code> class.
  Since I think both <code>Base</code> and <code>Derived</code> need to access this field, I define a <code>get</code> member function in <code>Base</code>, thus <code>Derived</code> can inherit it.
  Then I try to get the member field from different objects.</p>
  
  <p>The result shows that I still get original <code>b</code> in <code>Base</code> by <code>d.get()</code> instead of that in <code>Derived</code>, which is what I expected the code to do.
  Anything wrong with the code (or my understanding)? Is this behavior specified in the specification? What is the right way to override a member field and properly define its getter and setter?</p>