#include <iostream> #include <typeinfo> using namespace std; class Test { public: virtual ~Test() { } virtual void Out() { cout<<typeid(*this).name()<<endl; } Test() { cout<<typeid(*this).name()<<endl; } }; class FromTest : public Test { public: FromTest(){} }; void main() { // void * v=new Test; // Test * t=static_cast<Test *>(v); /**///// Test * t=(Test *)(v); // cout<<typeid(t).name()<<endl; // t->Out(); // int i; // cout<<typeid(i).name()<<endl; FromTest ft; Test * t;//=new FromTest; Test l; l.Out(); t=&ft; cout<<typeid(*t).name()<<endl; }
|