Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > typedef struct prototype?

Reply
Thread Tools

typedef struct prototype?

 
 
Dante
Guest
Posts: n/a
 
      03-29-2007
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;

 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      03-29-2007
* 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?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can *common* struct-members of 2 different struct-types, that are thesame for the first common members, be accessed via pointer cast to either struct-type? John Reye C Programming 28 05-08-2012 12:24 AM
CRTP-problem: How can the base class typedef a derived class' typedef? oor C++ 0 05-20-2008 12:39 PM
typedef struct {} SName; vs. struct SName{}; Steven T. Hatton C++ 2 08-03-2005 09:59 AM
Typedef A references struct B which references struct A which... DanielEKFA C++ 8 05-16-2005 10:26 AM
struct my_struct *p = (struct my_struct *)malloc(sizeof(struct my_struct)); Chris Fogelklou C Programming 36 04-20-2004 08:27 AM



Advertisments