赞
踩
问题:
定义了一个集合,存放了自定的数据,但是发现数据多的时候,只能插入两条数据;经过调研发现是自定义类型的小于操作符重载函数问题:之前判断的条件是,如果两个路径长度不相等,则表示该类型不一样;之后的条件是:如果两个路径名称不相等,则表示该类型不一样。
之前的代码如下:
- class UploadDirData
- {
- public:
- CLocalPath m_localPath;
- CServerPath m_remotePath;
- wxString dirName;
- UploadDirData& operator=(UploadDirData const& path) = default;
- bool operator<(UploadDirData const& op) const {return m_localPath.GetPath().length()>op.m_localPath.GetPath().length()?true:false;};
- };
改后的代码:
- class UploadDirData
- {
- public:
- CLocalPath m_localPath;
- CServerPath m_remotePath;
- wxString dirName;
- UploadDirData& operator=(UploadDirData const& path) = default;
- bool operator<(UploadDirData const& op) const {return (m_localPath.GetPath()+dirName)==(op.m_localPath.GetPath()+op.dirName)?false:true;};
- };
总结:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。