std::list 是一个双链表。这是否意味着应该可以通过仅访问迭代器来从列表中删除项目?
也许我的问题不够清楚。
#pragma once
#include <list>
typedef std::list<int> IntList ;
typedef IntList::iterator IntIterator;
class IntHiddenList
{
private:
IntList list;
public:
IntIterator AddInt(int x)
{
list.push_front(x);
return list.begin();
}
};
int main()
{
IntHiddenList a;
IntIterator it = a.AddInt(5);
// How would I go about deleting 5 from the list using only "it"?
}