typedef和常量指针
来源:互联网 发布:nginx addmodule 编辑:程序博客网 时间:2024/05/01 09:45
假设以下语句
Typedef string *ptr;
Const ptr cstr;
很多人都认为cstr的真实类型是str,但这是错误的。
Const string *c
#include <iostream>#include <cstring>using namespace std;int main(){string s("hello world");string s1("you can not point me");typedef string *ptrsing;const ptrsing cstr1 = &s;ptrsing const cstr2 =&s;string *const cstr3 =&s;cstr1 = &s1;cstr2 = &s1;cstr3 = &s1;return 0;}
错误的原因是把typedef当做文本扩展了,声明const ptr时,const修饰的是ptr指针,这是一个指针,因此定义等价于
String* const cstr。 0 0
- typedef和常量指针
- typedef、#define、指针常量和常量指针
- 关于常量指针 和 指针常量及 typedef 中一些难以理解的知识
- 指针常量与常量指针以及typedef定义的指针
- 关于指针(常量指针&&指针常量&&常量指针常量&&typedef)的总结
- 常量指针和指针常量
- 指针常量和常量指针
- 常量指针 和 指针常量
- 常量指针 和 指针常量
- 常量指针 和 指针常量
- 指针常量和常量指针
- 常量指针和指针常量
- 常量指针和指针常量
- 常量指针和指针常量
- 指针常量和常量指针
- 常量指针 和 指针常量
- 常量指针和指针常量
- 指针常量和常量指针
- 算法 约瑟夫环问题
- ssh 反向代理(转贴)
- Mysql实现数据的不重复写入(insert if not exists)以及新问题:ID自增不连续的解答
- “零距离”华为弹性计算云
- 2014 3.18开发碰到的问题
- typedef和常量指针
- 0xC0000005: 读取位置 0x00000000 时发生访问冲突
- GPDB管理员笔记(五)GP系统配置
- 用完Excel组件后 如何彻底关闭Excel进程
- JAVA dom4j 解析xml
- Reveal.app 试用期修改
- 第三周-项目4——长方柱类
- Java泛型
- 黑马程序员---ArrayList和HashSet的比较、hashCode的分析