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++) {
			arcs[i].toString();
		}
	}
};

struct arc {
	node *one;
	node *two;
	void toString() {
		cout << one->name << two->name;
	}
};

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 article has been dead for over six months. Start a new discussion instead.