以某种方式定义一个具有自己类型的结构作为字段? [英] define a struct that has its own type as a field somehow?

查看:87
本文介绍了以某种方式定义一个具有自己类型的结构作为字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


是否可以定义一个自身类型的结构?


所以它可以和如果是这样怎么做我想在这里做的事情?:


typedef struct mystruct {

int a;

mystruct * b;

} mystruct;


以上都行不通:


test。 c:7:未定义类型,找到`mystruct''

cpp-precomp:警告:智能预处理时出错,重试

基本模式

test.c:在函数main中:

test.c:7:在mystruct之前解析错误

test.c:7:警告:否结构或联合结束时的分号

test.c:顶级:

test.c:8:警告:数据定义没有类型或存储类

test.c:10:在返回之前解析错误


谢谢,本。

Hello,

Is it possible to define a struct that has a type of itself in it?

So is it possible and if so how to do what I''m trying to do here?:

typedef struct mystruct {
int a;
mystruct *b;
} mystruct;

The above doesn''t work:

test.c:7: undefined type, found `mystruct''
cpp-precomp: warning: errors during smart preprocessing, retrying in
basic mode
test.c: In function `main'':
test.c:7: parse error before "mystruct"
test.c:7: warning: no semicolon at end of struct or union
test.c: At top level:
test.c:8: warning: data definition has no type or storage class
test.c:10: parse error before "return"

Thanks, Ben.

推荐答案



" Ben" < x@x.abcwrote in message news:26 ****************** @ x.abc ...

"Ben" <x@x.abcwrote in message news:26******************@x.abc...

您好,


是否可以定义一个自身类型的结构?

谢谢,Ben。
Hello,

Is it possible to define a struct that has a type of itself in it?
Thanks, Ben.



试试这个

typedef struct _mystruct {

int a;

struct _mystruct * b;

} mystruct;


Serafeim

Try this
typedef struct _mystruct {
int a;
struct _mystruct *b;
} mystruct;

Serafeim


文章< 26 ** ****************@x.abc>,Ben< x@x.abcwrote:
In article <26******************@x.abc>, Ben <x@x.abcwrote:

您好,


是否可以定义一个具有自身类型的结构?


那么它是否有可能如果可以的话怎么做我想在这里做?:


typedef struct mystruct {

int a;

mystruct * b; < br $>
} mystruct;


以上都行不通:


test.c:7:未定义类型,发现`mystruct''

cpp-precomp:警告:智能预处理过程中的错误,重试

基本模式

test.c:In函数`main'':

test.c:7:在mystruct之前解析错误

test.c:7:警告:str结束时没有分号uct或union

test.c:顶级:

test.c:8:警告:数据定义没有类型或存储类

test.c:10:在返回之前解析错误


谢谢,Ben。
Hello,

Is it possible to define a struct that has a type of itself in it?

So is it possible and if so how to do what I''m trying to do here?:

typedef struct mystruct {
int a;
mystruct *b;
} mystruct;

The above doesn''t work:

test.c:7: undefined type, found `mystruct''
cpp-precomp: warning: errors during smart preprocessing, retrying in
basic mode
test.c: In function `main'':
test.c:7: parse error before "mystruct"
test.c:7: warning: no semicolon at end of struct or union
test.c: At top level:
test.c:8: warning: data definition has no type or storage class
test.c:10: parse error before "return"

Thanks, Ben.



糟糕,我刚刚在K& R书中找到了一个名为

" Self-referential Structures" ! :)我认为这将回答

问题......而且确实如此。答案是:


struct mystruct {

int a;

struct mystruct * b;

};

Oops, I''ve just found a section in the K&R book titled
"Self-referential Structures" ! :) I think that will answer the
question... and it does. The answer is:

struct mystruct {
int a;
struct mystruct *b;
};


在文章< eh *********** @ ulysses.noc.ntua.gr> ;, Papastefanos Serafeim

< se ****** @ otenet.grwrote:
In article <eh***********@ulysses.noc.ntua.gr>, Papastefanos Serafeim
<se******@otenet.grwrote:

" Ben" < x@x.abcwrote in message news:26 ****************** @ x.abc ...
"Ben" <x@x.abcwrote in message news:26******************@x.abc...

您好,


是否可以定义一个自身类型的结构?

谢谢,Ben。
Hello,

Is it possible to define a struct that has a type of itself in it?
Thanks, Ben.



试试这个

typedef struct _mystruct {

int a;

struct _mystruct * b;

} mystruct;


Serafeim


Try this
typedef struct _mystruct {
int a;
struct _mystruct *b;
} mystruct;

Serafeim



是的,谢谢。 ''struct''面前做到了。

谢谢,Ben。

Yup, thanks. ''struct'' infront does it.
Thanks, Ben.


这篇关于以某种方式定义一个具有自己类型的结构作为字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆