C++ Paste by downs
Description: test.cpp
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #include <iostream> #include <typeinfo> #include <cstdio> using namespace std; class A { public: int x; virtual void test(); virtual void test2(); ~A() { } }; void A::test() { } class B { public: int y; virtual void test2(); virtual void test3(A*); }; extern A *gen(); void cppfun() { A *a = gen(); printf("Size: %i\n", sizeof(A)); printf("x: %i\n", a->x); // printf("gen -> %p; calling\n", a); a->test(); a->test2(); asm("nop"); printf("name of a is %s (%p) from %p\n", typeid(*a).name(), typeid(*a).name(), &typeid(*a)); asm("nop"); printf("Time for dyncast!\n"); B *b = dynamic_cast<B*> (a); printf("y: %i\n", b->y); b->test3(a); printf("Done. \n"); } |