title: Pass an instance of a class deriving from a base class into a function
body: <p>I have a class hierarchy in my C++ program:</p>
  
  <pre><code>class DEBase {
  public:
      virtual double distance(vec3) = 0;
  };
  
  class Sphere : public DEBase {
  private: ...
  public:
      Sphere(...) {...}
      ...
      double distance(vec3 p) {...}
  };
  
  class XZPlane : public DEBase { 
  ... 
  public: 
      XZPlane(...) {...} 
      ... 
      double distance(vec3 p) {...} 
  } 
  ...
  </code></pre>
  
  <p>I want to pass any object deriving from <code>DEBase</code> into a function.</p>
  
  <pre><code>void addObject(DEBase o) {
      someVector.push_back(o);
  }
  </code></pre>
  
  <p>However, that does not work. I get an error message saying <code>error: cannot declare parameter 'o' to be of abstract type 'DEBase'</code></p>
  
  <p>When I Googled a bit, I found that you can pass in objects by reference. </p>
  
  <pre><code>void addObject(DEBase &amp;o) {
      someVector.push_back(&amp;o);
  }
  </code></pre>
  
  <p>The function now compiles properly, however invoking it seems impossible. 
  I tried <code>addObject(new Sphere(...))</code>, I tried <code>addObject(&amp;new Sphere(...))</code>, however, nothing works. </p>
  
  <p>How can I make it work?</p>