简体   繁体   English

声明一个unsigned int和一个数组的unordered_map(大小将不同)?

[英]Declaring an unordered_map of an unsigned int and an array (will have different sizes)?

Please ignore the unsigned int I put it there for completeness. 请忽略为完整性unsigned int我将其放在此处的unsigned int Anyways, my question is how do I declare an unordered_map if I want to store arrays of different sizes in it. 无论如何,我的问题是,如果我想在其中存储不同大小的数组,该如何声明unordered_map

I found a related answer on here: Using unordered_map on array of doubles 我在这里找到了一个相关的答案: 在双精度数组上使用unordered_map

However, the person said that the size of the array has to be declared as well (from what I understood is that, the array can only have the same size in the unordered_map ). 但是,该人说,还必须声明数组的大小(据我了解,数组在unordered_map只能具有相同的大小)。 Is there a way to do what I'm trying to accomplish? 有没有办法做我想完成的事情?

Update............................................ 更新............................................

I'm using "easygl" to draw somethings, one their functions fillpoly requires an array of points in order to draw the polygon. 我正在使用“ easygl”绘制事物,其功能fillpoly需要一组点才能绘制多边形。 I tried passing a vector, it didn't work. 我试图传递一个向量,但没有成功。 So I decided to use an array instead and it ended badly. 所以我决定改用数组,结果很糟糕。

If you need arrays with varying sizes, you typically use std::vector<>. 如果需要大小可变的数组,通常使用std :: vector <>。

So your data type you are looking for (a hash table from unsigned int to std::vector<>, containing, say... t_point... would look like this: 因此,您正在寻找的数据类型(从unsigned int到std :: vector <>的哈希表,其中包含... t_point ...看起来像这样:

typedef std::unordered_map<unsigned int, std::vector<t_point> > MyHashTable;

If you have a legacy C++/C api which needs a plain old array of your t_point, you can call it with a vector like this: 如果您有一个传统的C ++ / C api,它需要一个普通的t_point旧数组,则可以使用如下向量来调用它:

void Foo( t_point* array, size_t length );
std::vector<t_point> vec;
vec.push_back(t_point()); // just so our array is not empty...
Foo( &vec[0], vec.length() );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM