我正在使用multimap来存储一些使用openframeworks的数据。我能够创建multimap,但是当我尝试打印其中的数据时,我只能够打印内存地址并且不能获取值。无法打印multimap中的值
参考(部分 “在地图存储对象”):http://openframeworks.cc/ofBook/chapters/stl_map.html
h文件:
class xyPos {
public:
float x, y;
xyPos(float xPos, float yPos) {
x = xPos;
y = yPos;
}
//return ofVec2f(x, y);
};
static multimap<string, xyPos> posMap;
static multimap<string, xyPos>::iterator xyMapIterator;
cpp文件:
for(int i = 0; i < 10; i ++) {
for(int j = 0; j < 10; j ++) {
posMap.insert(make_pair("null", xyPos(i, j));
}
}
我也曾尝试:
for(int i = 0; i < 10; i ++) {
for(int j = 0; j < 10; j ++) {
xyPos *p = new xyPos(i, j);
xyMap.insert(make_pair("null", *p);
}
}
cout << "xyMap:\n";
for(xyMapIterator = xyMap.begin(); xyMapIterator != xyMap.end(); ++ xyMapIterator) {
cout << (*xyMapIterator).first << " => " << (*xyMapIterator).second << "\n";
} //will only compile with &(*xyMapIterator).second so i only have ["null", memory address] in the output
切是下降到[MCVE],发现它绝对没有任何关系'multimap'或迭代。 – juanchopanza