0

I'm trying to create a pointer that points to a 2D array. I looked at the question here A pointer to 2d array, but the solution provided gives me this error when compiling :

"error: incompatible types in assignment of ‘int ()[(((sizetype)(((ssizetype)n) + -1)) + 1)]’ to ‘int [(((sizetype)(((ssizetype)n) + -1)) + 1)]’"

The code is :

int multTable( int n ){
  int a = 10;
  int table[a][n];
  int *(tablepb)[n];
  tablepb = &(table[a-1]);
}

How can I make tablepb point to the last array in the first set of arrays of table?

Community
  • 1
  • 1
  • runtime-sized arrays are not (yet) part of standard C++. – Vaughn Cato Sep 25 '13 at 02:40
  • 1
    He means you cannot use variables like "a" and "n" for specifying the dimensions. You need to use something that can be considered constant by the compiler (such as numbers like int table[2][5]). –  Sep 25 '13 at 02:43

1 Answers1

0

Despite the non-standard use of runtime-sized arrays, you can achieve what you want with a simple int pointer and no need of the address of operator &:

int multTable( int n ){
  int a = 10;
  int table[a][n];
  int *tablepb = table[a-1];
}
goji
  • 6,911
  • 3
  • 42
  • 59