我有一個名爲Graph的類,在這個類中我有一個名爲V的成員,它是一個向量。我有一個名爲Edge的結構和一個Edges列表。如下所示:如何在C++中使用STL排序來排序類中的某些值?
struct Edge{
int u;
int v;
Edge(int u,int v){
this->u=u;
this->v=v;
}
};
struct Vertex{
int d;
int f;
.
.
.
}
class Graph{
vector <Vertex> V;
.
.
.
int edgeCmp(Edge* x,Edge* y){
return (V[x->v].d < V[y->v].d)?1:0;
}
void someFunction(){
list<Edge> backEdges;
backEdges.sort(&Graph::edgeCmp);
}
}
但它不工作!可能有人幫我做這樣的事情?我得到這個錯誤:
錯誤3錯誤C2064:術語不計算爲服用2個爲參數的C函數:\ Program Files文件\微軟的Visual Studio 9.0 \ VC \包括\ xutility 346
它無法理解我調用了需要2個參數的函數。我不知道爲什麼。
下次使用101010按鈕格式化代碼。 – kennytm 2010-06-05 07:57:25