Hi everyone,
How do you define two structs that include lists of or pointers to each other? I've tried including a forward declaration of one, and neither way works. Any help getting around this would be great, thanks in advance!

// struct arc; 

struct node {
	Vector<arc> arcs;
	void toString() {
		for(int i=0; i<arcs.size(); i++) {

struct arc {
	node *one;
	node *two;
	void toString() {
		cout << one->name << two->name;
9 Years
Discussion Span
Last Post by thingstealer

No, the answer is not that you're designing anything wrong. There is nothing wrong at all about mutually recursive data datatype definitions. There are inconveniences involved with circular data structures. And there were problems in your case.

thingstealer, a forward declaration doesn't work? Could you paste the exact code at http://codepad.org/, set it to C++ mode, and give the link? I'd like to see the error message.


Yeah, I do. Strange. When I run it (on XCode) it says error: forward declaration of arc and error: invalid use of undefined type 'struct arc'

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.