0

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
}
3
  • 1
    It is perfectly valid. What's the problem ? The error message you are getting may comes from another part of your code. Commented Apr 8, 2014 at 19:29
  • This is perfectly fine. But as as alternative, you can make bullets_onscreen as array of 4 bullet ? struct bullet bullets_onscreen[4]; Commented Apr 8, 2014 at 19:30
  • struct bullets_onscreen[2] //public --> struct bullets_onscreen[2]; //public Commented Apr 8, 2014 at 21:23

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I don't think so. Show an SSCCE.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.