简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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