我创建struct,如下所示
struct DoubleListDataNode
{
INT nSequenceID;
DOUBLE fTemp;
DOUBLE fHumi;
INT nTimeHour;
INT nTimeMiin;
INT nTS1;
INT nTS2;
};我创建了一个clist
typedef CList<DoubleListDataNode *, DoubleListDataNode *> listDoubleListDataNode;我创建了公共变量
listDoubleListDataNode gDoubleListDataNode;
DoubleListDataNode *pDoubleListDataNode;现在,我在列表中有数据
1 1.00 2.00 001H01M 1 2
2 1.00 2.00 002H01M 1 2
3 3.00 4.00 003H02M 3 4
4 3.00 4.00 004H02M 3 4
5 5.00 6.00 005H03M 5 6
6 5.00 6.00 006H03M 5 5如何使用CList中的Find功能查找nSequenceID =1或5?
没有findindex(0)和findindex(5)
我尝试使用gDoubleListDataNode(1,...),但它不起作用
谢谢
发布于 2013-04-17 12:24:25
CList类的Find()方法的实现是使用==运算符比较元素。在本例中,元素是指向结构的指针。Find()只是尝试将元素的地址与您传递给它的参数进行匹配。
这意味着,使用当前设计,如果不将gDoubleListDataNode中每个元素的地址存储在单独集合中的某个位置,即使您为结构定义了相等operator==,也无法定位该元素。
您有两个选择。
typedef CList<DoubleListDataNode, DoubleListDataNode&> listDoubleListDataNode;。当你这样做的时候,你必须用元素来填充它,而不是指针。但是,对于您的struct DoubleListDataNode,您必须定义operator=和operator==。当您定义后者时,您可以将其实现为使用CList的nSequenceIDtypedef CMap<int, int&, DoubleListDataNode *, DoubleListDataNode *> mapDoubleListDataNode;,这样您将能够使用MFC哈希表的强大功能在映射中快速定位所需的元素。但需要注意的是:地图中的值将是唯一的https://stackoverflow.com/questions/16051037
复制相似问题