1
我有一個列表結構:免費結構參數太多
typedef struct FaceNode{
FaceNode *next;
Face *aFace;
FaceNode *prev;
} FaceNode;
我用這個結構作爲成員:
FaceNode *myFaces;
並初始化它像這樣(在構造函數中)
this->myFaces = (FaceNode*)malloc(sizeof(FaceNode)*1);
後來我想釋放它,如下所示:
FaceNode *theCurrentFaceNode;
Face* theCurrentFace;
while(this->myFaces->next){
theCurrentFaceNode = this->myFaces;
theCurrentFace = theCurrentFaceNode->aFace;
this->myFaces = this->myFaces->next;
free(theCurrentFace);
free(theCurrentFaceNode);
}
現在我的IDE告訴我:「錯誤,函數調用過多的參數」免費調用。
這是什麼問題?
乾杯
問題是,這是「C with classes」,而不是C++。如果你沒有使用'this->',這只是C代碼。 – Xeo
它是一個命名空間問題?我的意思是,你的應用程序中定義了另一個「free()」,它沒有參數? –
正如@Xeo所暗示的,您應該在這裏使用'std :: list'。這也將使你在感覺到後,切換到比LINK清單更明智的數據結構更容易。 –