I'm still kind of new to C++ and I just can't figure out how to fix the error. Error I'm getings is saying "Invalid operands to binary expression". Does anyone have any idea on how to fix this? Any help is appreciated!! I'm using Xcode 4.5.2. Thanks!
[Edit] OK. I've updated the code below. I'm still getting the same error at the same line (find())... but here are the changes...
Vertex myVertex = new Vertex(1);
to
Vertex myVertex(1);
And added operator overload for <
struct Vertex {
int node;
bool known;
float distance;
Vertex *path;
Vertex(int n=0, bool known=false, duuble dist=INFINITY):
node(n), known(known), distance(dist) {}
};
struct Edge {
Vertex target;
float weight;
bool directed;
Edge(Vertex v2, float w, bool dir):target(v2), weight(w), directed(dir) {}
};
class Graph {
public:
/*unrelated members are removed*/
void findVertex() {
Vertex myVertex(1);
map<Vertex, vector<Edge> >::iterator itr;
itr = edges.find(myVertex); // <--- this is the line the error seems to related to
}
friend bool operator< (const Vertex& lhs, const Vertex& rhs) {
return lhs.node < rhs.node;
}
private:
/*unrelated members are removed*/
vector<Vertex> vertices;
map<Vertex, vector<Edge> > edges;
};