How to create Property of another class

Hi,
I have two class: Edge and Graph. Class Graph has one property of type Vector<Edge*>. But I am getting an error while Compiling. How do I resolve this.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

class Graph
{
public: 
vector <Edge *> graph;

void addAjEdges(orgNode,DstNode)
{
Edge *edge = new Edge(.....)
graph.push_back(edge);
}
};

class Edge
{
public:
int orgNode;
int destNode;
....

//constructor
Edge(OrinatNode,....)
{
 orgNode = OrinatNode;
....
}
};


I am not able to figure out what is the problem here. Need help please.
Put the declaration of edge before graph, or put a forward declaration of edge before graph.

Edit:

Ideally each class declaration should be in it's own header file. The implementations should be in their own .cpp files. Then include the appropriate header file where it is needed. Do fwd declarations to avoid circular dependencies.
Last edited on
Thanks. Got it resolved.
Topic archived. No new replies allowed.