title: Can I pass a reference to a map where the data is a pointer to a derived class?
body: <p>I'm wondering if it's possible to pass a reference to a map where the data is a pointer to a derived class? </p>
  
  <pre><code>  #include &lt;map&gt;
  
    class B {
  
    public:
  
    private:
      int x_;
    };
  
    class D : public B {
  
    public:
  
    private:
      int y_;
    };
  
    typedef std::map&lt;int, B*&gt; mapB_t;
    typedef std::map&lt;int, D*&gt; mapD_t;
  
    void foo(mapB_t&amp; inmap) {
      ;
    }
  
    int main() {
      mapB_t mapB;
      mapD_t mapD;
  
      mapB[0] = new B;
      mapD[0] = new D;
  
      foo(mapB);
      foo(mapD);
  
      return 0;
    }
  </code></pre>
  
  <p>I receive this compiler error:</p>
  
  <p>q.cc: In function 'int main()':
  q.cc:34: error: invalid initialization of reference of type 'mapB_t&amp;' from   expression of type 'mapD_t'
  q.cc:22: error: in passing argument 1 of 'void foo(mapB_t&amp;)'</p>