#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. .NET2.0引用.NET3.5的System.Core.dll&Dapper在.NET2.0下的配置

    微软MSDN对.NET2.0,3.0,3.5的描述: .NET Framework 版本 2.0.3.0 和 3.5 是使用同一 CLR 版本 (CLR 2.0) 生成的. 这些版本表示单个安装的连续 ...

  2. swiper 报错 ‘ Can't find variable: Dom7’

    一般报这个错是因为浏览器兼容问题,例如低版本的IE 现在通过npm install swiper 安装的版本都是4.x的 我的解决方法就是安装低版本的swiper, npm install swipe ...

  3. MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request; // 转换成多部分request异常

    原来是需要在springmvc中配置 <!-- multipartResolver上传文件 --> <bean id="multipartResolver" cl ...

  4. Uva11384 Help is needed for Dexter

    Dexter is tired of Dee Dee. So he decided to keep Dee Dee busy in a game. The game he planned for he ...

  5. 洛谷P1968 美元汇率[2017年4月计划 动态规划02]

    P1968 美元汇率 题目背景 此处省略maxint+1个数 题目描述 在以后的若干天里戴维将学习美元与德国马克的汇率.编写程序帮助戴维何时应买或卖马克或美元,使他从100美元开始,最后能获得最高可能 ...

  6. 【P3056】【USACO12NOV】笨牛Clumsy Cows

    P3056 [USACO12NOV]笨牛Clumsy Cows 题目描述 Bessie the cow is trying to type a balanced string of parenthes ...

  7. TSP

    #include <iostream> #include <limits.h> #include <string.h>; using namespace std; ...

  8. 合唱队形 ( 双向LIS )

    #include <iostream> #include <stdio.h> #include <algorithm> using namespace std; ] ...

  9. python-null

    很早之前,遇到过一个面试官问的python中有没有null,当时有点紧张,想成了None,就脱口而出是有的.今天遇到了none问题,所以就正好说一下. python中是没有NULL的. Python中 ...

  10. python3.7 安装gensim使用word2Vec库

    应用的文章(个人试验过,完全正确):https://radimrehurek.com/gensim/index.html#install