我对 C++ 还是很陌生,只是不知道如何解决这个错误。我得到的错误是说“二进制表达式的操作数无效”。有谁知道如何解决这个问题?任何帮助表示赞赏!我正在使用 Xcode 4.5.2。谢谢!
[编辑] 好的。我已经更新了下面的代码。我仍然在同一行(find())遇到相同的错误......但这里是变化......
Vertex myVertex = new Vertex(1);
至
Vertex myVertex(1);
并为 < 添加了运算符重载
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;
};