For a typedef
of a struct
in C, I can't do this:
typedef struct {
unsigned id;
node_t *left;
node_t *right;
} node_t;
because node_t
is not known until it is defined, so it can't be used in its own definition. A bit of a Catch-22. However, I can use this workaround to make the desired self-referential type:
typedef struct node_s node_t;
struct node_s {
unsigned id;
node_t *left;
node_t *right;
};
Similarly, I would like to do something like this for a C++ container referring to itself:
typedef pair<unsigned, pair<node_t *, node_t * > > node_t;
but of course, the compiler complains that it's never heard of node_t
before it's defined node_t
, as it would for the struct typedef
above.
So is there a workaround like for the struct
? Or some better way to do this? (And no, I don't want to use void
pointers.)