If you intent to use std::vector to store all the nodes, you may store the index of the neighbours.
Then to access, you've got three possibilities:
(1) make the vector of nodes "global"
(a) take a reference to the vector in foo()
(\alpha) store a pointer to the vector
Alternative (1) is not so bad at it appears.
1 2 3 4 5 6 7
|
class graph{
class node{
//...
};
std::vector<node> all_the_nodes_in_the_graph;
};
|
> I am afraid if I expand the Neighbor of any object in IH (...)
> I will change all address and make the pointer pointing to nowhere...
you may touch the nodes as much as you want, their address (or the ones stored in the neighbour vector) will not change
the problem is if you touch the vector of the nodes, like inserting elements.