Skip to content

Instantly share code, notes, and snippets.

@scooby
Created February 13, 2009 23:37
Show Gist options
  • Save scooby/64168 to your computer and use it in GitHub Desktop.
Save scooby/64168 to your computer and use it in GitHub Desktop.
tried different ways of registering classes, but the simple and stupid is the only reliable way
#include <iostream>
using namespace std;
class x {
public:
virtual const char* symbol(void) { return "x"; }
virtual void speak() { cout << "'x' says 'your mom'" << endl; }
private:
static char* sym;
};
class a : public virtual x {
public:
a() { };
virtual void speak() { cout << "'" << symbol() << "' says 'moo'" << endl; }
virtual const char* symbol(void) { return "a"; }
private:
static char* sym;
};
class b : public virtual x {
public:
b() { };
virtual void speak() { cout << "'" << symbol() << "' says 'boo'" << endl; }
virtual const char* symbol(void) { return "b"; }
private:
static char* sym;
};
class c : public virtual x {
public:
c() { };
virtual void speak() { cout << "'" << symbol() << "' says 'foo'" << endl; }
virtual const char* symbol(void) { return "c"; }
private:
static char* sym;
};
class symbol_table {
public:
static void reg(x* obj) {
string symbol = obj->symbol();
cout << symbol << " registered." << endl;
obj->speak();
}
static void load(void) {
reg(new a());
reg(new b());
reg(new c());
}
};
int main(void) {
symbol_table::load();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment