How to define a recursive type?

前端 未结 5 976
孤独总比滥情好
孤独总比滥情好 2021-01-01 14:45

I want to have a list. An entry in the list would store a value as well as an iterator to another entry in the list. How do I define this type? It\'d be something like this,

5条回答
  •  轮回少年
    2021-01-01 15:38

    You can do a trick like this, if you want:

    typedef list > MyList;
    typedef list >::const_iterator MyListIterator;
    
    int main() {
        MyList l;
        MyListIterator it;
        pair p(2, &it);
        l.push_back(p);
    }
    

    By the way, I prefer John Zwinck's solution.

提交回复
热议问题