#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

typeid, const_cast<Type>的使用的更多相关文章

  1. dede:channel的type改为son,currentstyle当前样式就不起作用

    我在修改得闲佬设计作品展示列表页的时候,遇到一个问题,就是channel的type改为son时,currentstyle属性不起作用,试了好久都没办法,后来上网找资料,就找到了解决方法,记录一下.   ...

  2. 易优CMS:type的基础用法

    [基础用法] 名称:type 功能:获取指定栏目信息 语法: {eyou:type typeid='栏目ID' empty='暂时没有数据'} <a href="{$field.typ ...

  3. C++ 表达式

    <C++ Primer 4th>读书摘要 C++ 提供了丰富的操作符,并定义操作数为内置类型时,这些操作符的含义.除此之外,C++ 还支持操作符重载,允许程序员自定义用于类类型时操作符的含 ...

  4. C++ QUICK REFERENCE

    C++ string 用法详解 字符串分割(C++)  C++ QUICK REFERENCE Matt Mahoney, mmahoney@cs.fit.edu DECLARATIONS enum ...

  5. C++ 第六课:C/C++关键字及其用法

    asm 插入一个汇编指令. auto 声明一个本地变量. bool 声明一个布尔型变量. break 结束一个循环. case 一个switch语句的一部分. catch 处理 thrown 产生的异 ...

  6. C++提供了四个转换运算符

    const_cast <new_type> (expression) static_cast <new_type> (expression) reinterpret_cast ...

  7. C/C++ 关键字的使用方法详解

    cppreference.com -> C/C++ 关键字 -> 细节 C/C++ 关键字 asm 语法: asm( "instruction" ); asm允许你在你 ...

  8. 谈谈SQL 语句的优化技术

    https://blogs.msdn.microsoft.com/apgcdsd/2011/01/10/sql-1/ 一.引言 一个凸现在很多开发者或数据库管理员面前的问题是数据库系统的性能问题.性能 ...

  9. Apache RewriteRule

    1.Rewirte主要的功能就是实现URL的跳转,它的正则表达式是基于Perl语言.可基 于服务器级的(httpd.conf)和目录级的 (.htaccess)两种方式.如果要想用到rewrite模块 ...

随机推荐

  1. Java数据结构和算法(七)--AVL树

    在上篇博客中,学习了二分搜索树:Java数据结构和算法(六)--二叉树,但是二分搜索树本身存在一个问题: 如果现在插入的数据为1,2,3,4,5,6,这样有序的数据,或者是逆序 这种情况下的二分搜索树 ...

  2. c#还有一点不太明白,既然开启了线程为何还要委托呢?

    2013-07-15 09:33threadroc | 浏览 1611 次 既然开启了线程为何还要委托呢?,开启线程本身不就是委托吗?为何委托要显示声明呢?Thread thread = new Th ...

  3. log4j2----JAVA日志打印

    注意:本篇文章是以log4j2.x 为例的,并不是log4j 1.x log4j 就是log for java  , log4j已经被移植到了C,C++,C#,Perl,Python和Ruby等语言中 ...

  4. css3 实现明信片正背面翻转

    <!DOCTYPE html> <html lang="zh-cn" style="width: 100%;height: 100%;"> ...

  5. file.length()方法返回0字节

    本地调试ok 扔到服务器上就返回0 初步估测是因为使用jnotify监控文件修改事件的时候,刚好文件被重命名了(下载完成后xxx.tmp,被改成正确的后缀名) 2019-7-20:不是上边说的那个亚子 ...

  6. spring boot定时任务解析

    在SpringBoot中定时任务一般使用的是@Scheduled注解. @Scheduled 1.注解内容: @Target({ElementType.METHOD, ElementType.ANNO ...

  7. Hystrix线程池配置

    Hystrix配置文件配置 断路器: hystrix.command.default.circuitBreaker.requestVolumeThreshold(当在配置时间窗口内达到此数量的失败后, ...

  8. 洛谷P1855 榨取kkksc03 [2017年4月计划 动态规划 09]

    P1855 榨取kkksc03 题目描述 洛谷的运营组决定,如果一名oier向他的教练推荐洛谷,并能够成功的使用(成功使用的定义是:该团队有20个或以上的成员,上传10道以上的私有题目,布置过一次作业 ...

  9. bzoj4974: [Lydsy八月月赛]字符串大师

    传送门 题目可转换为已知一个串kmp之后的nxt数组,求字典序最小的原串. 已知第i位结尾的串循环节长度位x,那么nxt[i]=i-x; 当nxt不为0时,s[i]=s[nxt[i]]; nxt为0时 ...

  10. 杨柳絮-Info:春天将不再漫天飞“雪”,济源治理杨柳絮在行动

    ylbtech-杨柳絮-Info:春天将不再漫天飞“雪”,济源治理杨柳絮在行动 1.返回顶部 1. 天气暖和了,连心情都是阳光的.然而,在这美好的时刻,漫天飞舞的杨柳絮,甚是煞风景.<ignor ...