我创建了一个结构体来保存表的行/列索引
struct itemIndex {
int row;
int col;
bool operator< (const itemIndex &i) const { if (this->col == i.col) return this->row < i.row; else return false; }
bool operator== (const itemIndex &i) const { return (this->row == i.row && this->col == i.col); }
};
现在,我已经创建了一个将索引作为键的映射,但是只有列1中的索引创建了键。但是,当调用索引为col = 0的值时,它似乎返回第一个插入的索引(row = 0, col = 0),我不知道为什么。下面是代码的实现:
itemIndex index;
index.row = pLVDispInfo->item.iItem;
index.col = pLVDispInfo->item.iSubItem;
//example index.row = 5, index.col = 0
bool found = false;
found = m_mSettingMap.find(index) != m_mSettingMap.end(); // returns true
int val = m_mSettingMap[index];
bool operator< (const itemIndex &i) const { if (this->col == i.col) return this->row < i.row; else return false; }
因此,如果col值匹配,则根据行进行子排序。正常的足够了。
但是如果col不匹配,你总是返回false?在这种情况下,我希望以col
为基础订购。
试题:
bool operator< (const itemIndex &i) const
{
if (col == i.col) return row < i.row;
return col < i.col;
}