首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

结构体中的继承?解决思路

2012-03-13 
结构体中的继承?typedefstructnode{structnode*next}nodetypedefstructwork_node{structnode*nextintjo

结构体中的继承?
typedef   struct   node   {
    struct   node   *next;
}   node;

typedef   struct   work_node   {
    struct   node   *next;
    int   jobnum;
}   wnode;

wnode   *mywork   =   (wnode   *)   queue_get(&queue);
                                ~~~~~~~~~~~~~~~这样的使用有什么道理?

queue_get()   从   queue   中取一个   node   *
queue的定义如下
typedef   struct   queue   {
    node   *head,   *tail;  
}   queue;

出处:http://www-128.ibm.com/developerworks/linux/library/l-posix3/

p.s.   组织问题的时候,又考虑了下,明白为何这样用了,不过始终觉得这种方式很诡异,不知道这是不是一种比较常见的技巧...?

[解决办法]
比较常见

struct xx
{
int len;
char aa[1];
}
用做变长数组
xx*p = (xx*)malloc(sizeof(xx)+1024);
这样p-> aa就有1028大小的空间了。

热点排行