C++ 技术中心

   :: 首页 :: 联系 ::  :: 管理
  160 Posts :: 0 Stories :: 87 Comments :: 0 Trackbacks

公告

郑重声明:本BLOG所发表的原创文章,作者保留一切权利。必须经过作者本人同意后方可转载,并注名作者(天空)和出处(CppBlog.com)。作者Email:coder@luckcoder.com

留言簿(27)

搜索

  •  

最新随笔

最新评论

评论排行榜

#include <iostream>
#include 
<typeinfo>
using namespace std;
class Test
{
public:
 
virtual ~Test()
 
{
 }

 
virtual void Out()
 
{
  cout
<<typeid(*this).name()<<endl;
 }

 Test()
 
{
  cout
<<typeid(*this).name()<<endl;
 }

}
;
class FromTest : public Test
{
public:
 FromTest()
{}
}
;
void main()
{
// void * v=new Test;
//    Test * t=static_cast<Test *>(v);
//// Test * t=(Test *)(v);
// cout<<typeid(t).name()<<endl;
// t->Out();
// int i;
// cout<<typeid(i).name()<<endl;
 FromTest ft;
 
 Test 
* t;//=new FromTest;
 Test l;
 l.Out(); 
 t
=&ft;
 cout
<<typeid(*t).name()<<endl;
}

posted on 2012-09-15 10:13 C++技术中心 阅读(1466) 评论(1)  编辑 收藏 引用 所属分类: C++ 基础

Feedback

# re: typeid用法 2014-06-22 09:27 kongguisheng
不喜欢这类文章,一点说明都没有。
给自己看的吗?  回复  更多评论
  


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理