Sorry for my inexperience with C++, but I spent quiet some time with solving a cyclic dependency issue and hence posing this.
I am trying to represent a Adjacency List in C++.
I have struct Node
,
struct Node{
int data;
unordered_set<Node, Hash> links;
bool operator == (Node const& other) const{
return (data == other.data);
}
Node(){
}
Node(int data){
this->data = data;
}
};
and I have my Hash
functor
struct Hash {
size_t operator()(const Node &node) const {
return node.data;
};
};
I noticed that Hash
uses Node
and Node
uses Hash
If for the purpose of this exercise I want to declare everything in a single file, which one should I declare first.
I tried forward declaration of both Hash
and Node
with defining either of them first, but none of them compiled.
PS: This is not homework, I'm trying to solve graph algorithm puzzles online