Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有一个 id:1 和坐标 1.0,2.0,3.0,4.0 的矩形。我可以为此使用 C++ Map 数据结构吗?或任何其他出路。我还需要找到给定坐标的键(或 id)。
struct rectangle { int x; int y; int w; int h; }; std::map< int, rectangle >myMap; | the ID
按 ID 访问,按值查找。尽管只有提供了所有坐标,您才能按值搜索。
如果您想通过 ID 查找坐标,可以使用 SingerOfTheFall 的答案。如果您发现通过坐标查找 ID,则需要覆盖操作符等于矩形。