#include <bits/stdc++.h>
using namespace std; class A {
public :
void Show() {
cout << "A" << endl;
}
} ; class CC {
public :
void Show() {
cout << "CC" << endl;
}
} ; class x {
public :
void Show() {
cout << "x" << endl;
}
} ; class {
} test; int main() {
long long a, *b = ;
int *c;
double *d;
cout << (typeid(a) == typeid(long long)) << endl;
cout << (typeid(a) == typeid(double)) << endl;
b = &a;
cout << (typeid(*b) == typeid(long long)) << endl;
cout << typeid(b).name() << endl;
cout << typeid(*b).name() << endl;
cout << typeid(c).name() << endl;
cout << typeid(*c).name() << endl;
cout << typeid(d).name() << endl;
cout << typeid(*d).name() << endl;
A t;
cout << typeid(t).name() << endl;
CC s;
cout << typeid(s).name() << endl;
x *p;
cout << typeid(p).name() << ' ' << typeid(*p).name() << endl;
class {
} temp;
cout << typeid(temp).name() << endl;
cout << typeid(test).name() << endl;
class {
} temp2;
cout << typeid(temp2).name() << endl;
class a {
} temp3;
cout << typeid(temp3).name() << endl;
cout << typeid(long).name() << endl;
unsigned long long l;
cout << typeid(l).name() << endl;
short z;
cout << typeid(z).name() << endl;
return ;
}

运行结果:


 Px
x
Pi
i
Pd
d
1A
2CC
P1x 1x
Z4mainEUt_
._125
Z4mainEUt0_
Z4mainE1a
l
y
s // 在ubuntu 13.10下的运行结果

const_cast<Type>去除const或volatile限制:

 #include <bits/stdc++.h>
using namespace std; char *Test(const char *s) {
char *t = const_cast<char *>(s);
*t = 'z';
return t;
} int main() {
const char *s1 = "abc";
const char s2[] = "cba";
//cout << Test(s1) << endl; // Run-Time Error
cout << Test(s2) << endl;
cout << s2 << endl;
//cout << Test("ABC") << endl; // Run-Time Error
return ;
}
 #include <bits/stdc++.h>
using namespace std; void change(const int *pt) {
int *pc = const_cast<int *> (pt);
*pc = ;
} int main() {
int pop1 = ;
const int pop2 = ;
cout << pop1 << ' ' << pop2 << endl;
change(&pop1);
change(&pop2);
cout << pop1 << ' ' << pop2 << endl;
return ;
}

——written by Lyon

最新文章

  1. 如何发布带静态资源的库——android 篇
  2. 【Prince2是什么】PRINCE2认证之Prince2衡量绩效的六大要素
  3. 自定义刻度的SeekBar
  4. SQL Server 2012 安装
  5. kmp
  6. js 小工具-- 原生 js 去除空格
  7. OpenGL2.0及以上版本中glm,glut,glew,glfw,mesa等部件的关系
  8. ldd查询命令或软件共享的函数库(动态)
  9. ✡ leetcode 156. Binary Tree Upside Down 旋转树 --------- java
  10. BZOJ 2120/BZOJ 2453
  11. Jquery 回到顶部
  12. Android Studio 设置LogCat 颜色
  13. 【HDU 4451 Dressing】水题,组合数
  14. 判图的连通性(dfs,并查集)
  15. Oracle常用函数:DateDiff() 返回两个日期之间的时间间隔自定义函数
  16. Caused by: java.lang.ClassNotFoundException: org.hibernate.engine.FilterDefinition
  17. 第五十五天 css基础入门
  18. Sqlite之事务
  19. C#,如何程序使用正则表达式如何使用匹配的位置的结果修改匹配到的值
  20. 开始学习Scheme

热门文章

  1. 读取复杂结构的yml配置项
  2. PHP--Smarty的template模式
  3. View的滑动原理和多种滑动方法
  4. Spring的IoC容器(转)BeanFactory
  5. Linux下安装jboss并设置自启动服务
  6. CentOS 7安装与配置Tomcat8
  7. js点击复制文本
  8. Hibernate_条件查询客户列表
  9. 【GDOI2017 day2】凡喵识图 二进制切分
  10. 高效整洁CSS代码原则 (下)