[ create a new paste ] login | about

Link: http://codepad.org/wDLD7NFw    [ raw code | output | fork ]

C++, pasted on Jan 15:
struct A
{
virtual void Foo() { std::cout << "Foo A\n"; }
};


struct B : A
{
virtual void Foo() { std::cout << "Foo B\n"; }
};


struct C : A
{
virtual void Bar() { std::cout << "Bar C\n"; }
};

int main()
{
A * a = new A();
A * b = new B();
A * c = new C();
a->Foo();
b->Foo();
c->Foo();
static_cast<C*>(c)->Bar();
delete a;
delete b;
delete c;
return 0;
}


Output:
1
2
3
4
Foo A
Foo B
Foo A
Bar C


Create a new paste based on this one


Comments: