刺激战场
六合彩
贵宾厅
  • 3228阅读
  • 1回复

Question11.11:I've got the declarations ,why is p turning out const,instead of characters? [复制链接]

上一主题 下一主题
离线那个谁
 

只看楼主 倒序阅读 使用道具 楼主  发表于: 2013-07-17
— 本帖被 tyrone2497谁 执行加亮操作(2013-07-19) —
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.    

离线那个谁

只看该作者 沙发  发表于: 2013-07-17
问题:我有这样的声明
             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中有一个指针。
快速回复
限100 字节
如果您在写长篇帖子又不马上发表,建议存为草稿
 
上一个 下一个