좌표를 키로 사용하여 std :: map을 만드는 것은 불가능합니다. (x + y + z)가 두 좌표에서 동일 할 경우 맵은 이전 좌표를 무시합니다. 예 :좌표가 키로 설정된 std :: map 만들기
map[Coordinate(1, 0, 0)] = object1;
map[Coordinate(0, 1, 0)] = object2;
map[Coordinate(0, 0, 1)] = object3;
이이 값 object3
키 등을 포함 Coordinate(0, 0, 1)
1 개 요소와 표준 :지도 당할 것이다. 이것을 방지하여 모든 값을 포함 할 수 있습니까?
#pragma once
struct Coordinate {
double x, y, z;
Coordinate(double x, double y, double z) : x(x), y(y), z(z) {}
bool operator<(const Coordinate& coord) const {
if(x + y + z < coord.x + coord.y + coord.z)
return true;
return false;
}
bool operator==(const Coordinate& coord) const {
if(x == coord.x && y == coord.y && z == coord.z)
return true;
return false;
}
inline bool isInRange(Coordinate coord, int range) const {
if(pow(coord.x - this->x, 2) + pow(coord.y - this->y, 2) + pow(coord.z - this->z, 2) <= range*range)
return true;
return false;
}
};
http://stackoverflow.com/questions/1380567/can-i-use-an-stl-map-if-i-plan-to-use-arbitrary-class- objects-as-the-key 대답 읽기 – UnknownError1337
당신의 문제는 당신의'<'연산자가 결정적이어야한다는 것입니다. '(x + y + z
Joe
1 차원 <연산자를 사용할 때 같기 때문입니다. –