Timeline for How do I declare a 2d array in C++ using new?
Current License: CC BY-SA 3.0
16 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Dec 12, 2023 at 0:10 | comment | added | Adiesha | @MohammadAlaggan Thank you so much for this, I have a follow up question. using arr2d = int(*)[5]; arr2d b = new int[3][5]; works but why doesn't int(*)[5] b = new int[3][5]; does not work | |
Sep 7, 2020 at 6:11 | comment | added | user1663023 |
So does it mean I don't need to delete each sub dimension arrays in a loop?
|
|
Feb 27, 2020 at 2:43 | comment | added | yath | why cant I do this though? => double(*)[2] array = new double[M][N](); | |
Feb 1, 2017 at 22:54 | comment | added | TimeString | Follow-up question: How should I free the array (created by new[10][10])? | |
Jan 7, 2017 at 8:12 | comment | added | juanchopanza | This answer would be better if it didn't make it seem it is only possible to do this since C++11. | |
Dec 4, 2015 at 5:45 | comment | added | legends2k | @vsoftco Yes, indeed, however the question was specifically about having both dimensions unknown at compile-time. | |
Dec 4, 2015 at 0:06 | comment | added | vsoftco |
@legends2k Only N has to be known, M can be non-const.
|
|
May 27, 2015 at 20:52 | history | edited | Emil Laine | CC BY-SA 3.0 |
typo fixes
|
Dec 13, 2014 at 8:20 | comment | added | 42n4 | How to pass twodimensional arrays to funcions in C++ (or C++11)? In C11 standard it can be done like that fn(int col,int row, int array[col][row]): stackoverflow.com/questions/16004668/… | |
Oct 26, 2013 at 14:18 | comment | added | legends2k | Problem with this solution is that the dimensions cannot be a run-time value, but should be known at compile-time. | |
Sep 30, 2013 at 18:09 | comment | added | Fozi |
+1: this is what the OP asked for. The proper type for this is either double (*)[M][N] or double(*)[][N] with M, N being constant expressions.
|
|
May 27, 2013 at 17:06 | comment | added | Mohammad Alaggan |
Can you use this then: using arr2d = double(*)[2]; arr2d array = new double[M][N];
|
|
May 27, 2013 at 14:38 | comment | added | Peter Smit | I need to do this in a class, hence I can't use auto. What would be the proper type for the array? | |
Apr 26, 2013 at 15:37 | history | edited | Mohammad Alaggan | CC BY-SA 3.0 |
added 1394 characters in body
|
Apr 26, 2013 at 15:12 | review | Low quality answers | |||
Apr 26, 2013 at 15:14 | |||||
Apr 26, 2013 at 14:57 | history | answered | Mohammad Alaggan | CC BY-SA 3.0 |