CS106B Graphs: for each with collection of pointers

Self-studying Stanford's online CS106B. This code is copied directly from the book, the last chapter on Graphs, but I can't get it to run and don't understand why. Any help appreciated.

In main(), first "for each" gives following error message:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

error C3285: for each statement cannot operate on variables of type 'Set<ElemType>' 
with [ ElemType=nodeT *  ]


int main()
	{
	graphT * airline = CreateAirlineGraph();
	for each ( nodeT * node in airline->nodes ) {  // <~~~~~~~~~~ error
		cout << node->name << " -> ";
		bool commaNeeded = false;
		for each ( arcT *arc in node->arcs ) {
			if ( commaNeeded ) cout << ", ";
			cout << arc->finish->name;
		commaNeeded = true;
		}
		cout << endl;
	}
	return 0;
	}


having defined in graph.h

struct graphT
	{
	Set<nodeT *> nodes;
	Set<arcT *> arcs;
	Map<nodeT *> nodeMap;
	};

struct nodeT
	{
	string name;
	Set<arcT *> arcs;
	};

struct arcT
	{
	nodeT * start;
	nodeT * finish;
	double cost;
	};


All along I have been trying to get the book's code to run, first, and then write my own for the assignments. So this is not homework, this is straight out of the text. Thanks.
for each ( nodeT * node in airline->nodes )
There's no such control structure in C++. C++11 was published a few days ago that adds ranged for, which is used to do iterate over containers, but the syntax looks nothing like this.
Thanks for the answer.

So I dug a little deeper. It's a precompiler macro called "foreach" not "for each", I had changed it, thinking it was a typo. The precompiler macro, written for every container to replace and simplify the iterator, is not found in the downloadable include files for some reason. Which is why it doesn't work, and the error C3285 refers to something else.

So then I expect I would have to go through the code and replace the foreach expression with an iterator. I'm not going to try to write a precompiler macro. Well, maybe.

Thanks for the support and solution.
Topic archived. No new replies allowed.