title: Why my code giving me a stackdump error when I run it?
body: <p>We are supposed to make classes of animals which inherit from classes of different types of animals, i.e the Dog class will inherit from the Carnivore class which will inherit from the Mammal class. I have tried using my classes in my own main function and they print out what they are supposed to say and their name but when I run my classes with my teacher's main file it tells me its dumping stack trace. </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;typeinfo&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  class Mammal {
  public:
      virtual string say() = 0;
      virtual string name() = 0;
  };
  
  class Carnivore : public Mammal {
  public:
      virtual string say() = 0;
      virtual string name() = 0;
  };
  
  class Canid : public Carnivore{
  public:
      virtual string say() = 0;
      virtual string name() = 0;
  };
  
  class Dog : public Canid{
  public:
      string say(){
          return "bark";
      }
      string name(){
          return "dog";
      }
  };
  
  class Fox : public Canid{
  public:
      Fox(){
          spoke = "ay";
      }
      std::string say(){
          spoke += spoke;
          return spoke;
      }
      std::string name(){
          return "fox";
      }
  private:
      std::string spoke;
  };
  
  class Feline : public Canid{
  public: 
      virtual string say() = 0;
      virtual string name() = 0;
   };
  
  class Cat : public Feline{
  public:
      std::string say(){
          return "moew";
      }
      std::string name(){
          return "cat";
      }
  };
  
  class Rodent : public Mammal{
  public: 
      virtual string say() = 0;
      virtual string name() = 0;
  };
  
  class Mouse : public Rodent{
  public:
      std::string say(){
          return "squeak";
      }
      std::string name(){
          return "mouse";
      }
  };
  
  Mammal* MammalFactory(const std::type_info&amp; ti){
  
      if(ti == typeid(Dog)){
          cout &lt;&lt; "running dog" &lt;&lt; endl;
          Dog D;
          Mammal* dog = &amp;D;
          return dog;
      }
      else if (ti == typeid(Fox)){
          cout &lt;&lt; "running fox" &lt;&lt; endl;
          Fox F;
          Mammal* fox = &amp;F;
          return fox;
      }
      else if (ti == typeid(Cat)){
          cout &lt;&lt; "running cat" &lt;&lt; endl;
          Cat C;
          Mammal* cat = &amp;C;
          return cat;
      }
      else if (ti == typeid(Mouse)){
          cout &lt;&lt; "running mouse" &lt;&lt; endl;
          Mouse M;
          Mammal* mouse = &amp;M;
          return mouse;
      }
      else{
          return NULL;
      }
  }
  
  int main(){
  
      int score = 90;
      std::vector&lt;Mammal*&gt; mammals;
      mammals.push_back(MammalFactory(typeid(Dog)));
      mammals.push_back(MammalFactory(typeid(Cat)));
      mammals.push_back(MammalFactory(typeid(Mouse)));
      Mammal* fox = MammalFactory(typeid(Fox));
  
      mammals.at(0)-&gt;name();
  
      for (std::vector&lt;Mammal*&gt;::iterator I = mammals.begin(); I != mammals.end(); ++I) {
          std::cout&lt;&lt;(*I)-&gt;name()&lt;&lt;" goes "&lt;&lt;(*I)-&gt;say()&lt;&lt;'\n';
      }
  
      //Check animal names
      if (mammals.at(0)-&gt;name() != "dog") {
          std::cout&lt;&lt;"Dog's name is incorrect! -10\n";
          score -= 10;
      }
      if (mammals.at(1)-&gt;name() != "cat") {
          std::cout&lt;&lt;"Cat's name is incorrect! -10\n";
          score -= 10;
      }
      if (mammals.at(2)-&gt;name() != "mouse") {
          std::cout&lt;&lt;"Mouse's name is incorrect! -10\n";
          score -= 10;
      }
      if (fox-&gt;name() != "fox") {
          std::cout&lt;&lt;"Fox's name is incorrect! -10\n";
          score -= 10;
      }
  
      //Fox part
  
      std::string thing1 = fox-&gt;say();
      std::string thing2 = fox-&gt;say();
  
      std::cout&lt;&lt;"What does the "&lt;&lt;fox-&gt;name()&lt;&lt;" say?\n";
      std::cout&lt;&lt;thing1&lt;&lt;"!\n";
      std::cout&lt;&lt;thing1&lt;&lt;"!\n";
      std::cout&lt;&lt;thing1&lt;&lt;"!\n";
      std::cout&lt;&lt;"What does the "&lt;&lt;fox-&gt;name()&lt;&lt;" say?\n";
      std::cout&lt;&lt;thing2&lt;&lt;"!\n";
      std::cout&lt;&lt;thing2&lt;&lt;"!\n";
      std::cout&lt;&lt;thing2&lt;&lt;"!\n";
  
      if (thing1 == thing2) {
          std::cout&lt;&lt;"Foxes don't say the same thing twice!\n";
          score -= 10;
      }
  
      for (std::vector&lt;Mammal*&gt;::iterator I = mammals.begin(); I != mammals.end(); ++I) {
          delete *I;
      }
      delete fox;
      return 0;
  }
  </code></pre>