>>22
#include <typeinfo>
#include <cstdio>
class a
{
virtual void foobar()
{
}
};
class b : public a
{
public:
void b_foo()
{
printf("is b\n");
}
};
class c : public a
{
public:
void c_foo()
{
printf("is c\n");
}
};
void test(a& bar)
{
printf("test %s\n", typeid(bar).name());
b* p1 = dynamic_cast<b*>(&bar);
if(p1)
p1->b_foo();
c* p2 = dynamic_cast<c*>(&bar);
if(p2)
p2->c_foo();
}
int main()
{
test(b());
test(c());
}
Oh shit nigger what is this black magic
Also
http://en.wikipedia.org/wiki/Liskov_substitution_principle