title: Destructor of class with vector of shared_ptr causes error
body: <p>I have a class Animal which is base class for few different Animals and a class Herd which stores shared_prt to animals in a vector. I'm unfamiliar with smart pointers but I had to use them in my code in orded to handle inheritance. It seemed to work fine but after my code gets to the destructor of "Herd" it throws an <a href="https://i.snag.gy/QlHaUN.jpg" rel="nofollow noreferrer">error</a>.
  What's wrong with it?</p>
  
  <pre><code>class Animal {
  public:
      Animal(string _sound) :
          sound(_sound) {}
      void give_sound() {
          cout &lt;&lt; sound &lt;&lt; " ";
      }
      bool operator==(Animal arg) {
          return (typeid(*this).name() == typeid(arg).name());
      }
  protected:
      string sound;
  };
  
  class Dog : public Animal {
  public:
      Dog() : Animal("woof") {}
  };
  
  class Cat : public Animal {
  public:
      Cat() : Animal("meow") {}
  };
  
  class Cow : public Animal {
  public:
      Cow() : Animal("moo") {}
  };
  
  class Herd {
  public:
      Herd() {}
      ~Herd() {
          vec.clear();
      }
  
      Herd operator+(Animal *arg) {
          shared_ptr&lt;Animal&gt; ptr(arg);
          vec.push_back(ptr);
          return *this;
      }
  
      void operator+=(Animal *arg) {
          shared_ptr&lt;Animal&gt; ptr(arg);
          vec.push_back(ptr);
      }
  
  
      void make_noise() {
          vector&lt;shared_ptr&lt;Animal&gt;&gt;::iterator v = vec.begin();
          while (v != vec.end()) {
              (*v)-&gt;give_sound();
              v++;
          }
          cout &lt;&lt; endl;
      }
  
  private:
      vector&lt;shared_ptr&lt;Animal&gt;&gt; vec;
  };
  
  int main() {
      Herd herd;
      Dog d1, d2;
      Cat c1, c2;
      cout &lt;&lt; "sound 1: " &lt;&lt; endl;
      herd.make_noise();
      herd += &amp;d1;
      herd += &amp;c1;
      cout &lt;&lt; "sound 2: " &lt;&lt; endl;
      herd.make_noise();
      herd += &amp;d2;
      herd += &amp;c2;
      cout &lt;&lt; "sound 3: " &lt;&lt; endl;
      herd.make_noise();
      //herd = herd - &amp;d1;
      //herd = herd - &amp;d2;
      cout &lt;&lt; "sound 4: " &lt;&lt; endl;
      herd.make_noise();
      return 0;
  }
  </code></pre>
  
  <p>edit: without vec.clear() it also crashes.</p>