Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

[C++] Pros and Cons?

Name: Anonymous 2012-05-18 22:10

Name: Anonymous 2012-05-20 3:28

>>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

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List