#include <iostream>

struct B
{
    int type;
	int val;
	B(int v) : type(0), val(v) {}
	B(int t, int v) : type(t), val(v) {};
};

struct D1 : public B
{
	D1(int v) : B(1, v) {}
	void add100() { val += 100; }
};

struct D2 : public B
{
	D2(int v) : B(2, v) {}
	void mul100() { val *= 100; }
};

void f(B &b)
{
	using namespace std;

	cout << "pre  = " << b.val << endl;
	switch (b.type) {
	case 1:
		static_cast<D1 &>(b).add100(); // downcast
		break;
	case 2:
		static_cast<D2 &>(b).mul100(); // downcast
		break;
	}
	cout << "post = " << b.val << endl;
}

int main(int argc, char **argv) {
	D1 d1(11);
	f(d1);

	D2 d2(22);
	f(d2);
	return 0;
}

