1

how can declare a 2nd or multidimensional array without first size in c++?

class numeric 
{
    public:
    int int_array_numbers[][];
    ...
};

Error message: declaration of 'int_array_numbers' as multidimensional array must have bounds for all dimensions except the first

jleahy
  • 16,149
  • 6
  • 47
  • 66
  • Hope this link is helpful [enter link description here][1] [1]: http://stackoverflow.com/questions/5737905/why-c-c-allows-omission-of-leftmost-index-of-a-multidimensional-array-in-a-fun – Raj Jun 25 '12 at 08:39

2 Answers2

11

You can't, C++ doesn't support VLA's (variable length arrays).

Use a std::vector<std::vector<int> > instead.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
5

you can declare your class as template from two arguments something like this

template <int N, int M>
class numeric 
{
public:
     int int_array_numbers[N][M];
...
};
Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
zapredelom
  • 1,009
  • 1
  • 11
  • 28
  • In which case, `N` and `M` have to be compile time constants. But it wouldn't be hard to make them arguments to the constructor, with a `std::vector` member initialized to `N * M`, and an overloaded `[]` operator which did the right thing. – James Kanze Jun 25 '12 at 08:55