title: Inheritance and derived attribute disappearing in C++
body: <p>I'm quite new to the concept of inheritance, and to C++ too, so my problem may be really stupid...</p>
  
  <pre><code>class A {
      public :
          A() {}
          A(string name) {name_ = name}
  
      private :
          string name_;
  }
  
  class B : public A {
      public :
          B() {}
          B(string name, int number) {
              name_ = name;
              number_ = number;
          }
  
      private :
          string name;
          int number;
  }
  
  class C {
      public :
          C() {}
          void addClass(int id, A* a) {
              map[id] = a;
          }
  
      private :
          Hash_Map&lt;int, A*&gt; map;
  }
  
  void main() {
      C* c = new C();
      for (int i = 0; i &lt; 10; i++) {
          B* b = new B("randomName", 50);
          c-&gt;addClass(i, b); //1st problem
          delete b;            //2nd problem
      }
  
  }
  </code></pre>
  
  <p>1st problem : shouldn't "map" in "c" keep the attribute "number" from the class "B"? I know I put A* in parameter, but if I had several class that derived from A, how should I do it?</p>
  
  <p>2nd problem : All of my attributes in "map" seem to get random values when I delete "b". I'm guessing the problem is that I need to copy "b" into a new object, but how can I do it if I have "A*" as my addClass() parameter? My pointer b seems to be converted into its parent class</p>
  
  <p>EDIT : had to change several things in my code that I forgot...</p>