繁体   English   中英

另一个结构内的结构数组

[英]struct array inside another struct

我正在尝试使用内部其他结构创建一个结构。

    struct bullet{
        char bullet_sprite[100];
        int pos_x;
        int pos_y;
        int ace_x;
        int tag;
    };


  struct bullets_onscreen{
        struct bullet v[2];
        struct bullet a[2];
  };

我收到此错误:

错误:数组类型的元素类型不完整

这可行吗?

示例代码:

//Calling functions
struct bullets_onscreen[2] //public 

struct bullet bala[1];
init_bullet(&bala,_player);
set_bullet_on_screen(&bala);

void set_bullet_on_screen(struct bullet *_bullet){
        array_bullet[1] = _bullet;
}
void init_bullet(struct bullet *_bullet, struct player *_player){
        //inits all bullet components
}

如所写,您的代码很好。 大概在实际代码中,您已经颠倒了两个结构定义的顺序。 此代码产生您报告的错误:

struct bullets_onscreen{
    struct bullet v[2];
    struct bullet a[2];
};

struct bullet{
    char bullet_sprite[100];
    int pos_x;
    int pos_y;
    int ace_x;
    int tag;
};

按照在问题中执行的顺序定义结构,然后将编译代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM