class dependcies

I want to create two classes, Node and Link.
Node can contain Link
Link can contain Node
how to achieve this ??
For example:
This won't compile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<vector>
using namespace std;

class Node{
public:
	int id;
	std::vector<Link*> path;
};

class Link{
public:
	Node* endA;
	Node* endZ;


};
Use a class forward reference. LIke this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Link;  //forward reference
class Node{
public:
	int id;
	std::vector<Link*> path;
};

class Link{
public:
	Node* endA;
	Node* endZ;


};


This tells the compiler that there is a class Link so that make it OK to allow a Link*. But that's about it. If you start using Link methods, then you need to show the compiler the class declaration.
Got it, thanks!
Topic archived. No new replies allowed.