有基本物件
class MyShape;
和三個繼承物件
class MyLine : MyShape;
class MyRect : MyShape;
class MyEllipse : MyShape;
MyShape *aShape = (MyShape*)new MyLine;
MyShape *aShape = (MyShape*)new MyRect;
MyShape *aShape = (MyShape*)new MyEllipse;
要判斷 aShape 是哪種類別, 可用:
typeid(*aShape) == typeid(MyLine)
使用時要
#include
是 class type_info
也可以用 cout << typeid(*aShape).name() << endl;
直接印出類別名稱.
沒有留言:
張貼留言