#include <iostream>
 
struct Base {
  enum Type {
    FOO = 0,
    BAR = 1
  };
  virtual ~Base() {}
  virtual Type type() const = 0;
  int value_;
};
 
struct Foo : Base { 
    Foo() { value_ = 33; }
    virtual Type type() const { return FOO; }
};
 
struct Bar : Base { 
    Bar() { value_ = 44; }
    virtual Type type() const { return BAR; }
};
 
int main() {
    Foo foo;
    Bar bar;
    Base & b = foo;
    std::cout << b.type() << ", " << b.value_ << "\n";
    b = bar;
    std::cout << b.type() << ", " << b.value_ << "\n";
    return 0;
}
