Redian新闻
>
请问可以这样定义struct吗?
avatar
请问可以这样定义struct吗?# Programming - 葵花宝典
c*k
1
想在struct a里定义一个dynamic array of pointers,每个pointer都指向另一个
struct b
typedef struct {
b **p
} a;
typedef struct {
int i;
} b;
那么我以后能不能用这个格式来访问
a *ptr;
ptr->p[3]->i;
avatar
l*d
2
I think it is ok, except that the definition of b should appear before the d
efinition of a in this case.

【在 c***k 的大作中提到】
: 想在struct a里定义一个dynamic array of pointers,每个pointer都指向另一个
: struct b
: typedef struct {
: b **p
: } a;
: typedef struct {
: int i;
: } b;
: 那么我以后能不能用这个格式来访问
: a *ptr;

avatar
c*k
3
But I got the compile time error :(
"dereferencing pointer to incomplete type"

d

【在 l*****d 的大作中提到】
: I think it is ok, except that the definition of b should appear before the d
: efinition of a in this case.

avatar
l*d
4
Have you moved definition b in front of that of a?
Also have you allocated memory for array p[]?

【在 c***k 的大作中提到】
: But I got the compile time error :(
: "dereferencing pointer to incomplete type"
:
: d

avatar
c*k
5
I forgot to cast, thank you ^^

【在 l*****d 的大作中提到】
: Have you moved definition b in front of that of a?
: Also have you allocated memory for array p[]?

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。