Skip to content

Instantly share code, notes, and snippets.

@szastupov
Created May 20, 2010 08:25
Show Gist options
  • Save szastupov/407338 to your computer and use it in GitHub Desktop.
Save szastupov/407338 to your computer and use it in GitHub Desktop.
struct Foo {
virtual int bar() = 0;
};
struct A : public Foo {
int bar() { return 1; }
};
struct B : public Foo {
int bar() { return 2; }
};
struct FooDescr {
const char *name;
FooDescr(const char *name) : name(name) {}
virtual Foo* create() = 0;
};
template <class T>
struct FooDescrT : public FooDescr {
FooDescrT(const char *name) : FooDescr(name) {}
Foo* create() { return new T(); }
};
FooDescr* fd[] = { new FooDescrT<A>("Adfsdf"), new FooDescrT<B>("dfsdf") };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment