收藏 (0) +1 (0) +1 (0) +1
收藏成功查看收藏>>

正在阅读:经典:教你理解复杂的C/C++声明经典:教你理解复杂的C/C++声明

2004-07-16 10:15 出处:CSDN 作者:陆其明译 责任编辑:linjixiong

  注: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的妙用

  typedef给你一种方式来克服“*只适合于变量而不适合于类型”的弊端。你可以如下使用typedef:


typedef char * PCHAR;
PCHAR p,q;

  这里的p和q都被声明为指针。(如果不使用typedef,q将被声明为一个char变量,这跟我们的第一眼感觉不太一致!)下面有一些使用typedef的声明,并且给出了解释:


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 returns 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.

  typedef经常用在一个结构声明之前,如下。这样,当创建结构变量的时候,允许你不使用关键字struct(在C中,创建结构变量时要求使用struct关键字,如struct tagPOINT a;而在C++中,struct可以忽略,如tagPOINT b)。


typedef struct tagPOINT
{
    int x;
    int y;
}POINT;

POINT p; /* Valid C code */


察看评论详细内容 我要发表评论
作者笔名 简短内容 发表时间
:

键盘也能翻页,试试“← →”键

关注我们

最新资讯离线随时看 聊天吐槽赢奖品
手机访问回到顶部