SEMAN

曾经沧海难为水、除却巫山不是云

C++博客 首页 新随笔 联系 聚合 管理
  9 Posts :: 3 Stories :: 24 Comments :: 0 Trackbacks

 

char ** p1;                                   //    pointer to pointer to char
const char **p2;                           //    pointer to pointer to const char
char * const * p3;                         //    pointer to const pointer to char
const char * const * p4;                //    pointer to const pointer to const char
char ** const p5;                          //    const pointer to pointer to char
const char ** const p6;                 //    const pointer to pointer to const char
char * const * const p7;                //    const pointer to const pointer to char
const char * const * const p8;       //    const pointer to const pointer to const char


注:p1是指向char类型的指针的指针;
        p2是指向const char类型的指针的指针;
        p3是指向char类型的const指针;
        p4是指向const char类型的const指针;
        p5是指向char类型的指针的const指针;
        p6是指向const char类型的指针的const指针;
        p7是指向char类型const指针的const指针;
        p8是指向const char类型的const指针的const指针。

typedef char * a;       // a is a pointer to a char 

typedef a b();            
// b is a function that returns a pointer to a char

typedef b 
*c;            // c is a pointer to a function that returns a pointer to a char 

typedef c d();           
// d is a function returning a pointer to a function that returns a pointer to a char 

typedef d 
*e;           // e is a pointer to a function returning a pointer to a function that a pointer to a char 

e var[
10];               // var is an array of 10 pointers to functions returning pointers to  functions returning pointers to chars.


原文地址:http://www.codeproject.com/cpp/complex_declarations.asp

posted on 2005-11-02 22:08 味全每日C++ 阅读(2313) 评论(9)  编辑 收藏 引用 所属分类: STL

Feedback

# re: 比饶口令还饶口的复杂声明 2005-11-02 22:54 huangyi
所以不喜欢c++  回复  更多评论
  

# re: 比饶口令还饶口的复杂声明 2005-11-04 10:34 任我行
晕,谁定义的这种变量?
拉出来弹JJ。
  回复  更多评论
  

# re: 比饶口令还饶口的复杂声明 2005-11-06 13:38 neoragex2002
http://neoragex2002.cnblogs.com/archive/2005/11/06/269974.html
推荐看看这里,如何一劳永逸的理解这些复合定义。  回复  更多评论
  

# re: 比饶口令还饶口的复杂声明 2006-05-20 08:24 水手
高是在是高!  回复  更多评论
  

# re: 比饶口令还饶口的复杂声明 2006-09-04 14:11 blues
const 完成这样,你也是古今第一人了!
其实都是 char** p,只要把 const 去了,再加上就行了!  回复  更多评论
  

# re: 比饶口令还饶口的复杂声明 2006-12-21 09:03 pengkuny
不错  回复  更多评论
  

# re: 比饶口令还饶口的复杂声明 2006-12-21 10:16 Dain
从右向左读  回复  更多评论
  

# re: 比饶口令还饶口的复杂声明 2008-09-20 21:41 yecq
呵呵,这只是简单声明,真正复杂的是函数,指针,数组混在一起的声明。
不过这只是看起来麻烦,其实只要好好看看K&R的书后面的文法,就会很清楚的,分析复杂声明是一个机械活动,而不是一个项脑力劳动,毕竟机器是会通过一些固定的方法识别这些复杂声明的。  回复  更多评论
  

# re: 比饶口令还饶口的复杂声明 2009-06-17 21:27 insulted
不错!谢谢!  回复  更多评论
  


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理