#include <memory>

class generic {
    class underlying_base {
    public:
        virtual ~underlying_base(){}
        virtual void SomeGenericMethod()=0;
    };
    template <class T>
    class underlying_impl : public underlying_base {
        T data;
    public:
        underlying_impl(const T& d) :data(d) {}
        virtual void SomeGenericMethod() 
        {return data.SomeGenericMethod();}
    };
    public:
        std::unique_ptr<underlying_base> data;

        template < class T > void setOther(const T& other) {
            data.reset(new underlying_impl<T>(other));
        }

        void doSomethingWithOther() {
            data->SomeGenericMethod();
        }
};

#include <iostream>
struct Bar {
    void SomeGenericMethod() {std::cout << "BAR\n";}
};

int main(int argc, char **argv) {
    generic fObj;
    Bar bObj;
    fObj.setOther(bObj);
    fObj.doSomethingWithOther();
    return 0;
}