// RTTI.cpp - a demonstration of RTTI in C++
#include <typeinfo.h>
#include <iostream.h>
#include <string.h>
class graphicImage
{
protected:
char name[80];
public:
graphicImage()
{
strcpy(name,"graphicImage");
}
virtual void display()
{
cout << "Display a generic image." << endl;
}
char* getName()
{
return name;
}
};
//----------------------------------------------------------------
class GIFimage : public graphicImage
{
public:
GIFimage()
{
strcpy(name,"GIFimage");
}
void display()
{
cout << "Display a GIF file." << endl;
}
};
class PICTimage : public graphicImage
{
public:
PICTimage()
{
strcpy(name,"PICTimage");
}
void display()
{
cout << "Display a PICT file." << endl;
}
};
//----------------------------------------------------------------
void processFile(graphicImage *type)
{
if (typeid(GIFimage) == typeid(*type))
{
((GIFimage *)type)->display();
}
else if (typeid(PICTimage) == typeid(*type))
{
((PICTimage *)type)->display();
}
else
cout << "Unknown type! " << (typeid(*type)).name() << endl;
}
void main()
{
graphicImage *gImage = new GIFimage();
graphicImage *pImage = new PICTimage();
//processFile(gImage);
//processFile(pImage);
}
RTTI.rar_rtti
版权申诉
72 浏览量
2022-09-23
07:22:39
上传
评论
收藏 5KB RAR 举报
Kinonoyomeo
- 粉丝: 76
- 资源: 1万+
最新资源
- python-leetcode面试题解之第157题用Read4读取N个字符-题解.zip
- python-leetcode面试题解之第156题上下翻转二叉树-题解.zip
- python-leetcode面试题解之第155题最小栈-题解.zip
- python-leetcode面试题解之第153题寻找旋转排序数组中的最小值-题解.zip
- python-leetcode面试题解之第152题乘积最大子数组-题解.zip
- python-leetcode面试题解之第151题反转字符串中的单词-题解.zip
- python-leetcode面试题解之第150题逆波兰表达式求值-题解.zip
- python-leetcode面试题解之第149题直线上最多的点数-题解.zip
- python-leetcode面试题解之第148题排序链表-题解.zip
- python-leetcode面试题解之第147题对链表进行插入排序-题解.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈