title: C++11 vector of smart pointer
body: <p>Suppose we have the following codes. We have following classes</p>
  
  <ul>
  <li>Animal as AbstractClass</li>
  <li>Dog and Bird which is subclass of Animal </li>
  <li>Zoo which keeps all animals</li>
  </ul>
  
  <p>_</p>
  
  <pre><code>class Animal
  {
  public:
      Animal();
      void HasWings() = 0;
  };
  
  class Bird : public Animal
  {
  public:
      Bird() : Animal() {}
      void HasWings() override { return true; }
  };
  
  class Dog : public Animal
  {
  public:
      Dog() : Animal() {}
      void HasWings() override { return false; }
  };
  
  class Zoo
  {
  public:
      Zoo() {}
      void AddAnimal(Animal* animal) { _animals.push_back(animal); }
      ...
      std::vector&lt;Animal*&gt; _animals;
  };
  
  void myTest()
  {
      Zoo myZoo;
      Bird* bird = new Bird();
      Dog* dog = new Dog();
  
      myZoo.AddAnimal(bird);
      myZoo.AddAnimal(dog);
  
      for (auto animal : myZoo._animals)
      {
          ...
      }
      ...
  }
  </code></pre>
  
  <p>I hope to replace vector of pointers by vector of smart pointers. i.e, </p>
  
  <pre><code>std::vector&lt;std::shared_ptr&lt;Animal&gt;&gt; _animals;
  </code></pre>
  
  <p>How do we change the code for Zoo and myTest?
  I find difficulty on updating the code, especially the method "AddAnimal" in Zoo class</p>
  
  <pre><code>auto bird = std::make_shared&lt;Bird&gt;();
  auto dog = std::make_shared&lt;Dog&gt;();
  myZoo.AddAnimal(bird);
  myZoo.AddAnimal(dog);
  </code></pre>
  
  <p>bird and dog are different type</p>