G ++编译器无法识别C++中的枚举类型

Cha*_* Le 1 c++ enums templates enumeration

我试图使用枚举类型和模板类,但我不知道为什么以下代码不起作用:

#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;
}
Run Code Online (Sandbox Code Playgroud)

Eclipse在'CATEGORY DEFINITION'部分中返回错误:

../src/multilist.cpp:109:错误:'ID'不是类型
../src/multilist.cpp:110:错误:'OCCUPATION'不是类型
../src/multilist.cpp:111 :错误:'LOCATION'不是一种类型

Ben*_*son 5

您需要将这些构造函数调用放在以下构造函数中Multilist: Multilist(...) : catId(ID), catOccupation(OCCUPATION), ...并从声明中删除它们.您当前使用看起来像你正试图返回申报功能mlCat<>从而ID等.al被解释为参数的类型.