typedef struct prototype?

Discussion in 'C++' started by Dante, Mar 29, 2007.

  1. Dante

    Dante Guest

    I am having trouble compiling the following 2 structs because they
    both refer to each other. Is it possible to have some kind of struct
    prototype to get this to compile? I tried "struct Object_Children;" at
    the top line, along with a few other things, but I still get compile
    errors.

    typedef struct _Object
    {

    Object_Children children;

    } Object;


    typedef struct _Object_Children
    {

    Object *children_array; //array of Objects

    } Object_Children;
     
    Dante, Mar 29, 2007
    #1
    1. Advertising

  2. * Dante:
    > I am having trouble compiling the following 2 structs because they
    > both refer to each other. Is it possible to have some kind of struct
    > prototype to get this to compile? I tried "struct Object_Children;" at
    > the top line, along with a few other things, but I still get compile
    > errors.
    >
    > typedef struct _Object
    > {
    >
    > Object_Children children;
    >
    > } Object;
    >
    >
    > typedef struct _Object_Children
    > {
    >
    > Object *children_array; //array of Objects
    >
    > } Object_Children;


    struct Object;

    struct ObjectChildren
    {
    Object* childrenArray;
    };

    struct Object
    {
    ObjectChildren children;
    };

    -- or --

    struct Object
    {
    struct Children
    {
    Object* childrenArray;
    };

    Children children;
    };

    Note that a names starting with underscore followed by uppercase are
    reserved for the implementation, not to be used by you.

    Also, instead of raw array of children, consider using

    std::vector<Object> children;




    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Mar 29, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DanielEKFA
    Replies:
    8
    Views:
    616
    DanielEKFA
    May 16, 2005
  2. Chris Fogelklou
    Replies:
    36
    Views:
    1,391
    Chris Fogelklou
    Apr 20, 2004
  3. Steven T. Hatton
    Replies:
    2
    Views:
    681
  4. June Lee
    Replies:
    2
    Views:
    809
    Jim Cobban
    Apr 13, 2008
  5. Replies:
    9
    Views:
    200
    Thomas 'PointedEars' Lahn
    May 26, 2006
Loading...

Share This Page