#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. DevCloud会员权益升级!日常领码豆,轻松换好礼!

    为了回馈每一位用户的使用和支持, 华为云DevCloud上线了会员中心, 大家在会员中心可以通过完成任务赚取码豆, 并在兑换商城兑换精美礼品. 如何通过任务获得码豆? 我们为大家准备了各种日常任务, ...

  2. jquery版本冲突问题

    开发过程中,我们常常会遇到这种问题: 我们需要做一个新的功能,需要插入一个新的插件,使用新版的jquery,但原版的jquery已经被很多函数使用,不能直接修改.这时候我们可以现将$转移给$170($ ...

  3. Delphi 设计模式:《HeadFirst设计模式》Delphi7代码---策略模式之MiniDuckSimulator[转]

     1  2{<HeadFirst设计模式>之策略模式 }  3{ 本单元中的类为策略类           }  4{ 编译工具: Delphi7.0           }  5{ E- ...

  4. python类相关总结(持续更新)

    __init__() 构造函数 __new__ () 在构造函数之前,用来创建对象的,返回值是一个对象,__init__指的是将__new__返回的对象作为self来传入函数中,后续参数两者都可以一样 ...

  5. proteus 8.8 直装版提示Symbol $MKRORIGIN used but not found in libraries 安装后没有库

    用管理员运行程序,然后再通过菜单打开仿真文件是没问题. 解决方法:通常的安装目录是C:\Program Files (x86)\Labcenter Electronics\Proteus 8 Prof ...

  6. Python实例 复制文件

    import  shutil import  os import  os.path src = " d:\\download\\test\\myfile1.txt " dst = ...

  7. python实例 文件处理

    对比Java,python的文本处理再次让人感动 #! /usr/bin/python spath="D:/download/baa.txt" f=open(spath," ...

  8. Leetcode606.Construct String from Binary Tree根据二叉树创建字符串

    你需要采用前序遍历的方式,将一个二叉树转换成一个由括号和整数组成的字符串. 空节点则用一对空括号 "()" 表示.而且你需要省略所有不影响字符串与原始二叉树之间的一对一映射关系的空 ...

  9. node安装镜像和webpack

    先安装node 安装指南:https://npm.taobao.org/

  10. 理解async和await

    async 是“异步”的简写,而 await 可以认为是 async wait 的简写. 所以应该很好理解 async 用于申明一个 function 是异步的,而 await 用于等待一个异步方法执 ...