我在cv6.0编译不能通过???
我在cv6.0编译不能通过???
我在cv6.0编译不能通过???
2018-10-16
#include<cstdio> #include<cstring> #include<iostream> #include<typeinfo> using namespace std; class Movable{ public: virtual void mmove() = 0; }; class Bus:public Movable { public: ~Bus(){} virtual void mmove(){ cout << "Bus -- move" << endl; } void carry(){ cout << "Bus -- carry" << endl; } }; class Tank:public Movable { public: ~Tank(){} virtual void mmove(){ cout << "Tank -- move" << endl; } void shot(){ cout << "Tank -- shot" << endl; } }; void dosomething(Movable *obj){ obj->mmove(); // cout << typeid(*obj).name() << endl; if( typeid(*obj) == typeid(Bus) ){ Bus *bus = dynamic_cast<Bus*>(obj); bus->carry(); }else if( typeid(*obj) == typeid(Tank) ){ Tank *tank = dynamic_cast<Tank*>(obj); tank->shot(); } } int main(){ Bus *bus = new Bus(); Tank *tank = new Tank(); dosomething(bus); dosomething(tank); delete bus; delete tank; bus = NULL; tank = NULL; return 0; }
举报