64,654
社区成员
发帖
与我相关
我的任务
分享
class CWidget
typedef std::map<int, CWidget> MyMap
int key1, key2, key3;
MyMap::iterator It = m_map.begin();
int insertIndex = 0;
for (; It != m_map.end(); it++, insertIndex++)
{
if (!列表.find(it->first))
{
// 在列表中没有找到相应值,需要插入新值
列表.insert(insertIndex, it->second)
}
}
typedef std::list<Widget> MList;
MList::iterator it1, it2
it2 - it1;
既然it2 - it1操作没有被明确规定,我想就不能通过索引号(下标)来确定list中某个Widget的位置。
好像vector支持这个操作,但又会在随机位置删除元素,所以用vector不太合适。
我还是换换思路在那个不支持排序的列表上想办法吧[/quote]
list又没有下标,就算是MFC的CList的GetAt函数,内部也是用遍历来完成移动到某个位置的。
如果你不用频繁在头部或中间插入元素的话,可以改用vector
typedef std::list<Widget> MList;
MList::iterator it1, it2
it2 - it1;
既然it2 - it1操作没有被明确规定,我想就不能通过索引号(下标)来确定list中某个Widget的位置。
好像vector支持这个操作,但又会在随机位置删除元素,所以用vector不太合适。
我还是换换思路在那个不支持排序的列表上想办法吧