找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 274|回复: 1

Question11.11:I've got the declarations ,why is p turning out const,instead of characters?

[复制链接]

210

主题

371

回帖

0

积分

管理员

积分
0
发表于 2013-7-17 20:31:24 | 显示全部楼层 |阅读模式
Q: I've got the declarations
                       typedef char *charp;
                       const charp p;
Why is p turning out const, instead of the characters pointed to?

A: typedef substitutions are not purely textual. (This is one of the advantages of typedefs; see question 1.13.) In the declaration                     
                                              const charp p;
p is const for the same reason that const int i declares i as const. The typedef'ed declaration of p does not ``look inside'' the typedef to see that there is a pointer involved.     

210

主题

371

回帖

0

积分

管理员

积分
0
 楼主| 发表于 2013-7-17 20:49:19 | 显示全部楼层
问题:我有这样的声明
             typedef char *charp;
                       const charp p;
为什么p是const而不是其指向的字符为const?
回答:typedef替换并不是纯文本的。(这也正是typedefs的一个优点;参考问题1.13。)在声明中
                const charp p;
p是const的原因和const int i声明了i为const是一样的。typedef’ed 声明的p不会“向内查看”typedef中有一个指针。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

果子博客
扫码关注微信公众号

Archiver|手机版|小黑屋|风叶林

GMT+8, 2026-2-2 04:20 , Processed in 0.072821 second(s), 20 queries .

Powered by 风叶林

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表