title: invalid initialization of reference of type std::vector
body: <p>This is the error:</p>
  
  <blockquote>
    <p>DummyService.hpp:35: error: invalid covariant return type for 'virtual
    std::vector &lt; ResourceBean*,
    std::allocator &lt; ResourceBean*> >&amp; DummyService::list(const std::string&amp;)'</p>
  </blockquote>
  
  <pre><code>class Bean {
  public:
      typedef std::string Path;
      virtual ~Bean() {};
      virtual const Path&amp; getPath() = 0;
      virtual const std::string&amp; getName() = 0;
  protected:
      Bean();
  };
  
  class ResourceBean: public Bean {
  public:
      ResourceBean(const Path&amp; path, const std::string&amp; contents) :
              _path(path), _contents(contents) {
      }
      virtual ~ResourceBean() { }
      virtual const Path&amp; getPath();
      virtual void setPath(const Path&amp; path);
      virtual const std::string&amp; getName();
      virtual void setName(const std::string&amp; name);
  private:
      Path _path;
      std::string _name;
  };
  </code></pre>
  
  <p>The above <code>Bean</code> classes are data representations, and they are used by two different layers. One layer uses the <code>Bean</code> interface, just to access the getters for the data. The <code>ResourceBean</code> is accessed by the data access object (DAO) classes, which take the data from a database (for example), and fill in the <code>ResourceBean</code>. </p>
  
  <p>One responsibility of the DAO is to list the resources given a certain path:</p>
  
  <pre><code>class Service {
  protected:
      /*
       * Service object must not be instantiated (derived classes must be instantiated instead). Service is an interface for the generic Service.
       */
      Service();
  
  public:
      virtual std::vector&lt;Bean*&gt;&amp; list(const Bean::Path&amp; path) = 0;
      virtual ~Service();
  };
  
  class DummyService: public Service {
  public:
      DummyService();
      ~DummyService();
  
      virtual std::vector&lt;ResourceBean*&gt;&amp; list(const ResourceBean::Path&amp; path);
  };
  </code></pre>
  
  <p>I think the problem is related with the fact that in <code>std::vector&lt;ResourceBean*&gt;</code> the compiler does not understand that <code>Bean</code> is actually the base class of <code>ResourceBean</code>.</p>
  
  <p>Any suggestions? I've read to some similar topics but some of the solutions did not work in my case. Please point out if I have missed something. Thank you in advance.</p>