0

I know how to get the size of a static array etc, but my problem is that I can't get the size of an array of vectors defined like that:

vector<int> * grid = new vector<int> [pixels_num];

Since the size of each element of this size differs how can I get even the first dimension's length (in other words how many vectors there are in this array). My final goal is to compute the total length of this array (that is how many integers are stored in this struct). Is it preferable to use a vector of vectors even if I can have a static array of vectors?

iiirxs
  • 4,493
  • 2
  • 20
  • 35
  • The same way you get the size of an array of ints, doubles or chars. i.e you can't. You need to keep track of the length. – juanchopanza May 12 '15 at 14:26
  • Use a vector of vectors, or something else specifically designed for such use cases, like Boost.MultiArray – Praetorian May 12 '15 at 14:29
  • 2
    If you change `grid` to a `vector>` then you can use `vector::size()` within `std::accumulate` to get the total number of elements. I'd post it as an answer, but your post has been closed, so please see [this link](http://cpp.sh/6xxj) for an example. – Cory Kramer May 12 '15 at 14:33

0 Answers0