typedef struct prototype?

D

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

Alf P. Steinbach

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top