C++ Instantiating childs of an abstract class with pure virtual functions
<p>I have an abstract class, let it be for example <strong>Animal</strong>. An Animal has a pure virtual function <em>eat</em>, which every animal must implement if they don't want to starve. I ensure that only a child of an Animal can be instantiated by this way:</p>

<p>Animal.hpp</p>

<pre><code>class Animal
{

public:

    enum eAnimal{
        CAT=0,
        DOG=1,
        BIRD=2
    };

    // Instantiates the desired animal.
    static Animal GetAnimal(const int animal);

    virtual void Eat() const = 0;

protected:

    Animal();
};
</code></pre>

<p>Animal.cpp</p>

<pre><code>Animal Animal::GetAnimal(const int animal)
{
    switch(animal)
    {
    case CAT:
        return Cat();
    case DOG:
        return Dog();
    case BIRD:
        return Bird();
    default:
        cerr &lt;&lt; "Animal not recognized." &lt;&lt; endl;
        exit(-1);
    }
}

Animal::Animal()
{}
</code></pre>

<p>With this, a <strong>Cat</strong> would be:</p>

<p>Cat.hpp</p>

<pre><code>class Cat : public Animal
{

public:

    Cat();

    void Eat() const;
};
</code></pre>

<p>Cat.cpp</p>

<pre><code>Cat::Cat() : Animal()
{}

void Cat::Eat() const
{
    // The cat eats.
}
</code></pre>

<p>However this code doesn't work, it gets an error <em>invalid abstract return type 'Animal'</em> in <em>GetAnimal</em>, because Animal is abstract and can't be instantiated, altough my API ensures it won't.</p>

<p>Which smart solutions may this problem have? I can do the function <em>Eat</em> not pure and give it a default implementation, but I'd like not to do it.</p>