我試圖用枚舉類型和模板類,但我不知道爲什麼下面的代碼不工作:G ++編譯器無法識別枚舉類型在C++
#include <stdio.h>
#include <string.h>
class Multilist {
//TYPE DEFINITION
struct mlNode; //forward declarations
struct dlNode;
template <class T> struct mlCat;
typedef char tstr[21]; //our string type
enum catIterator {ID=0, OCCUPATION,LOCATION};
struct mlNode { //Multilist Node
tstr name; int id;
mlNode* p[3]; //next nodes
mlNode* n[3]; //previous nodes
dlNode* h[3]; //h[i] point to the entry in category i
mlNode(tstr sName, int sId) {
strcpy(name,sName); id=sId; //nOccupation=snOccupation; nId=snId; nLocation=snLocation;
}
};
// One class to rule them all =)
template <class T> struct mlCat { //Multilist Category
catIterator c;
mlCat(catIterator tc): head(0), c(tc) {};
struct dlNode { //list node
dlNode *next;
T data; mlNode *link; //data & link to the record in the db
dlNode(T d, mlNode *l, dlNode *n=0): link(l),data(d),next(n) {};
} *head;
};
//CATEGORY DEFINITION
mlCat<int> catId(ID);
mlCat<tstr> catOccupation(OCCUPATION);
mlCat<tstr> catLocation(LOCATION);
};
int main(int narg, char * arg[]) {
return 0;
}
在Eclipse中返回一個錯誤在「類別定義」部分:
../src/multilist.cpp:109: error: ‘ID’ is not a type
../src/multilist.cpp:110: error: ‘OCCUPATION’ is not a type
../src/multilist.cpp:111: error: ‘LOCATION’ is not a type
確實如此。謝謝 :) – 2011-04-11 04:48:23