#include <iostream>
#include <memory>
#include <cstdlib>
#include <ctime>

using namespace std;

struct IFoo {
    virtual void foo() const = 0;
};

struct FooA : public IFoo {
    void foo() const {cout << "FooA::foo()\n";}
};

struct FooB : public IFoo {
    void foo() const {cout << "FooB::foo()\n";}
};

enum FOO_TYPE
{
    FOO_A, FOO_B
};

std::unique_ptr<IFoo> get_a_foo()
{
    using ptr_type = std::unique_ptr<IFoo>;

    switch (std::rand() % 2)
    {
    case FOO_A: return ptr_type(new FooA);
    case FOO_B: return ptr_type(new FooB);

    // or, if your compiler supports the C++14 [i]make_unique[/i]:
    // case FOO_A: return make_unique<FooA>();
    // case FOO_B: return make_unique<FooB>();
    default: return nullptr;
    }
}

int main(int argc, char **args)
{
    std::srand(std::time(0));

    for (unsigned i = 0; i < 10; ++i)
    {
        auto foo_thing = get_a_foo();

        foo_thing->foo();
        std::cout << '\n';
    }
}