简体   繁体   English

另一个结构内的结构数组

[英]struct array inside another struct

I'm trying to create an structure with other structures inside. 我正在尝试使用内部其他结构创建一个结构。

    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];
  };

I get this error: 我收到此错误:

error: array type has incomplete element type 错误:数组类型的元素类型不完整

Is this posible to do? 这可行吗?

Example code: 示例代码:

//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
}

As written your code is fine. 如所写,您的代码很好。 Presumably in the actual code you have reversed the order of the two struct definitions. 大概在实际代码中,您已经颠倒了两个结构定义的顺序。 This code produces the error you report: 此代码产生您报告的错误:

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;
};

Define the structs in the order that you did in the question and your code will compile. 按照在问题中执行的顺序定义结构,然后将编译代码。

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

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