0

Please ignore the unsigned int I put it there for completeness. Anyways, my question is how do I declare an unordered_map if I want to store arrays of different sizes in it.

I found a related answer on here: Using unordered_map on array of doubles

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). 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. I tried passing a vector, it didn't work. So I decided to use an array instead and it ended badly.

Community
  • 1
  • 1
ConfusedCoder
  • 337
  • 2
  • 3
  • 12
  • Just providing a link (even a site internal one), makes your question pretty non self contained, and hard to grasp. Please provide all of the relevant parts or code, compiler errors, etc in your question (additionally link elsewhere if appropriate). VTC. – πάντα ῥεῖ Feb 14 '15 at 23:10

1 Answers1

1

If you need arrays with varying sizes, you typically use 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:

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:

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() );
BitTickler
  • 10,905
  • 5
  • 32
  • 53