wordpress全站公告,dedecms 网站地图 模板,企业网站代建设,md风格的wordpress主题为什么要自定义QMap的 key和value呢?因为在某些应用场景,基本数据类型的key和value并不能满足要求,比如座位在第几行、第几列,座位上人的姓名、职务;二维坐标系中散点的横坐标、纵坐标,散点的id、result。即key和value是一种多对多的关系。
#include QMap
#incl…为什么要自定义QMap的 key和value呢?因为在某些应用场景,基本数据类型的key和value并不能满足要求,比如座位在第几行、第几列,座位上人的姓名、职务;二维坐标系中散点的横坐标、纵坐标,散点的id、result。即key和value是一种多对多的关系。
#include QMap
#include QDebug#include tuple
#include stringstruct CustomKey
{CustomKey(int x, int y){this-x = x;this-y = y;} bool operator (const CustomKey key) const{// 先比较x与key.x// 然后比较y与key.yreturn std::tie(this-x, this-y) std::tie(key.x, key.y);} int x = 0;int y = 0;
};struct CustomValue
{std::string name;std::string duties;
};int main(int argc, char *argv[])
{QMapCustomKey, CustomValue positionMap;CustomValue user;user.name = "csdn";user.duties = "website";positionMap[CustomKey(0, 0)] = user;user.name = "cao shang pa#