RTTI(執行時期型別辨識)

ayiayi6386 2003-12-12 05:09:46
我在看《深入浅出MFC》但有些词语实在难理解请你帮帮我!
RTTI(執行時期型別辨識)到底是啥!请说得详细些谢谢!
...全文
31 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangyangcheng 2003-12-30
  • 打赏
  • 举报
回复
//RTTI是否可與polymorphics機制搭配使用?

#include <iostream>
#include <typeinfo>
using namespace std;
class Base
{
public:
Base( int x ):_x( x )
{
}
virtual const char* what_am_i() const
{
return typeid(*this).name();
}
protected:
int _x;
};

class Derived:public Base
{
public:
Derived( int x ):Base( x )
{
}
virtual const char* what_am_i() const
{
return typeid(*this).name();
}

};

int main()
{
Base _base(0);
Derived _derived(1);
Base *_pBase = &_derived;
if ( typeid( *_pBase ) == typeid( Derived ) )
cout << _base.what_am_i() << endl;
return 0;
}
smalltalk 2003-12-13
  • 打赏
  • 举报
回复
RTTI就是能够使得c++的运算付dynamic_cast<type>能够正常工作的技术。无它。
cpsoft 2003-12-12
  • 打赏
  • 举报
回复
RTTI是否被98年C++定义为标准功能?我知道VC6不是标准C++,那么VC7中是否实现了这个功能??
是什么关键字!
muzili 2003-12-12
  • 打赏
  • 举报
回复
简单认为就是判断一个未知的类对象指针究竟是什么类对象的指针
chenmujian81 2003-12-12
  • 打赏
  • 举报
回复
运行时识别---对象的类型。
zhukeke 2003-12-12
  • 打赏
  • 举报
回复
RTTI是一块静态数据,它记录了类的名字,版本号等信息。仅此而已。

64,637

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧