// 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
版权申诉
144 浏览量
2022-09-24
00:55:00
上传
评论
收藏 540B RAR 举报
alvarocfc
- 粉丝: 112
- 资源: 1万+
最新资源
- CDIO项目-编码电子锁-设计报告模板
- CGE 可计算一般均衡模型的基本原理与编程
- 数据库管理工具:dbeaver-ce-23.2.1-stable.x86-64.rpm
- 数据库管理工具:dbeaver-ce-23.2.1-macos-x86-64.dmg
- 数据库管理工具:dbeaver-ce-23.2.1-macos-aarch64.dmg
- 基于SpringBoot的旅游网站的设计与实现
- 数据库管理工具:dbeaver-ce-23.2.0-stable.x86-64.rpm
- 全国大学生建模大赛题目.pdf
- 数据库管理工具:dbeaver-ce-23.2.0-macos-x86-64.dmg
- 数据库管理工具:dbeaver-ce-23.2.0-macos-aarch64.dmg
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈