title: Return child class into base class object
body: <p>I am trying to get my head around some inheritance problem in C++:</p>
  
  <p>Consider a base class <code>Foo()</code> with a method <code>method()</code> and its derived class <code>Bar</code>. Now I override the method in <code>Bar</code>. </p>
  
  <pre><code>class Foo{
  public:
      double method();
  }
  
  class Bar public: Foo
  {
  public:
      double method()
  }
  </code></pre>
  
  <p>And a function like this:</p>
  
  <pre><code>Foo get_bar(){
      Bar bar()
      return bar
  }
  </code></pre>
  
  <p>Calling the function <code>get_bar()</code> I'd like to be able to call <code>Bar::method()</code></p>
  
  <pre><code>Foo foo = get_bar();
  foo.method() (-&gt; which should be Bar::method)
  </code></pre>
  
  <p>Is this possible? And if, how? I think I am making a fundamental mistake here which I don't see. Thanks!</p>