title: Inheritance in std::map with base class as value
body: <p>Here is a code:</p>
  
  <pre><code>class Base {
      public:
          long index;
  };
  class Derived : public Base {
      public:
          bool value;
  };
  
  void call(map&lt;char *, Base *&gt; *base) {
      map&lt;char *, Base *&gt;::iterator it = base-&gt;begin();
      cout &lt;&lt; it-&gt;second-&gt;index &lt;&lt; endl;
  }
  void test(void) {
      map&lt;char *, Derived *&gt; *d = new map&lt;char *, Derived *&gt;;
  
      call(d);
  }
  </code></pre>
  
  <p>Compiler alerts an error:</p>
  
  <pre><code>error C2664: 'call' : cannot convert parameter 1 from 'std::map&lt;_Kty,_Ty&gt; *' to 'std::map&lt;_Kty,_Ty&gt; *'
  1&gt;        with
  1&gt;        [
  1&gt;            _Kty=char *,
  1&gt;            _Ty=Derived *
  1&gt;        ]
  1&gt;        and
  1&gt;        [
  1&gt;            _Kty=char *,
  1&gt;            _Ty=Base *
  1&gt;        ]
  1&gt;        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
  </code></pre>
  
  <p>I understand why this error is happened.
  I do not understand how to make it work. What kind of cast and how to use it?</p>
  
  <p><strong>UPD</strong></p>
  
  <p>I'm sorry for imprecision, let me explain more details.
  I have two sets of data represented by ClassA and ClassB.
  Both of these classes have one common member - an "index", for example.
  Both sets are wrapped into a maps (special thanks to Rob for a significant correction with char*):</p>
  
  <pre><code>std::map&lt;char, ClassA&gt;
  std::map&lt;char, ClassB&gt;
  </code></pre>
  
  <p>Sometime I need to iterate over both maps to get a value of a common member "index".
  I'm trying to avoid code duplication and make just one function to iterate over both maps.</p>
  
  <p>I thought I may extract a superclass with a common member and make a function with parameter like this one:</p>
  
  <pre><code>std::map&lt;char, SuperClassAB&gt;
  </code></pre>
  
  <p>or</p>
  
  <pre><code>std::map&lt;char, SuperClassAB&gt;::iterator
  </code></pre>
  
  <p>But looks like it's a bad idea.</p>
  
  <p><strong>UPD2</strong></p>
  
  <p>One smart guy gave me the solution:</p>
  
  <pre><code>template &lt;class T&gt;
  void call(map&lt;char, T&gt; *base) {
      map&lt;char, T&gt;::iterator it = base-&gt;begin();
      cout &lt;&lt; it-&gt;second-&gt;index &lt;&lt; endl;
  }
  void test(void) {
      map&lt;char, Derived *&gt; d;
      call(&amp;d);
  }
  </code></pre>