dynamic-arrays

Why does C++ allow variable length arrays that aren't dynamically allocated?

萝らか妹 提交于 2019-12-17 07:52:34
问题 I'm relatively new to C++, and from the beginning it's been drilled into me that you can't do something like int x; cin >> x; int array[x]; Instead, you must use dynamic memory. However, I recently discovered that the above will compile (though I get a -pedantic warning saying it's forbidden by ISO C++). I know that it's obviously a bad idea to do it if it's not allowed by the standard, but I previously didn't even know this was possible. My question is, why does g++ allow variable length

ReDim Preserve to a Multi-Dimensional Array in Visual Basic 6

一曲冷凌霜 提交于 2019-12-17 07:34:26
问题 I'm using VB6 and I need to do a ReDim Preserve to a Multi-Dimensional Array: Dim n, m As Integer n = 1 m = 0 Dim arrCity() As String ReDim arrCity(n, m) n = n + 1 m = m + 1 ReDim Preserve arrCity(n, m) Whenever I do it as I have written it, I get the following error: runtime error 9: subscript out of range Because I can only change the last array dimension, well in my task I have to change the whole array (2 dimensions in my example) ! Is there any workaround or another solution for this?

ReDim Preserve to a Multi-Dimensional Array in Visual Basic 6

a 夏天 提交于 2019-12-17 07:34:12
问题 I'm using VB6 and I need to do a ReDim Preserve to a Multi-Dimensional Array: Dim n, m As Integer n = 1 m = 0 Dim arrCity() As String ReDim arrCity(n, m) n = n + 1 m = m + 1 ReDim Preserve arrCity(n, m) Whenever I do it as I have written it, I get the following error: runtime error 9: subscript out of range Because I can only change the last array dimension, well in my task I have to change the whole array (2 dimensions in my example) ! Is there any workaround or another solution for this?

Pointer-to-pointer dynamic two-dimensional array

大城市里の小女人 提交于 2019-12-17 06:27:08
问题 First timer on this website, so here goes.. I'm a newbie to C++ and I'm currently working through the book "Data structures using C++ 2nd ed, of D.S. Malik". In the book Malik offers two ways of creating a dynamic two-dimensional array. In the first method, you declare a variable to be an array of pointers, where each pointer is of type integer. ex. int *board[4]; ..and then use a for-loop to create the 'columns' while using the array of pointers as 'rows'. The second method, you use a

Pointer-to-pointer dynamic two-dimensional array

冷暖自知 提交于 2019-12-17 06:27:06
问题 First timer on this website, so here goes.. I'm a newbie to C++ and I'm currently working through the book "Data structures using C++ 2nd ed, of D.S. Malik". In the book Malik offers two ways of creating a dynamic two-dimensional array. In the first method, you declare a variable to be an array of pointers, where each pointer is of type integer. ex. int *board[4]; ..and then use a for-loop to create the 'columns' while using the array of pointers as 'rows'. The second method, you use a

How to add JSON data in select and option tag?

雨燕双飞 提交于 2019-12-14 03:46:13
问题 I have this html code: <html> <head> <link rel="stylesheet" type="text/css" href="CarInfoStyle.css"> </head> <script src="CarInfoJavascript.js"></script> <body> <div class="searchfilter"> <div class="searchwrapper"> <select class="selectClass" id="minYear"> <option value="minYear">Select Year</option> <option value="(All)">ALL</option> <option value="2015">2015</option> <option value="2014">2014</option> <option value="2013">2013</option> <option value="2012">2012</option> <option value="2011

The array is static, but the array size isn't know until runtime. How is this possible?

三世轮回 提交于 2019-12-13 12:03:05
问题 This has been troubling me for a while. It goes to the heart of my (lack of) understanding of the difference between static and dynamic memory allocation. The following array is an ordinary static array, which should mean the memory is allocated during compile time, correct? Yet, I've set it up so that the user enters the array size at runtime. #include <iostream> using namespace std; int main() { cout << "how many elements should the array hold? "; int arraySize; cin >> arraySize; int arr

First Dimension Unsized Class Member

笑着哭i 提交于 2019-12-13 04:35:30
问题 I have a class I'm converting: class MyClass { public:: void foo( void ) { static const char* bar[][3] = { NULL }; func( bar ); } }; Now I want to make bar a member variable, but because the first dimension is unsized I can't. I also can't pass const char** bar[3] to void func( const char* param[][3] ) . Is there a workaround for this that I'm unaware of, or is this a situation where I must use a method static ? Edit in Response to Jarod42 Matching the initialization of bar is my problem here

Memory allocation for 2D array in C

让人想犯罪 __ 提交于 2019-12-13 04:13:34
问题 I am writing a multithreaded C program and I have an error. I have a 2D array array worker_table declared globally as: int **worker_table; And allocated in main as follows: worker_table = (int**) calloc(number_of_workers*2,(sizeof(int))); This is the worker function: void *Worker(void *worker_id) { my_id = (int)worker_id; //id of the worker printf("Line 231\n"); printf("My id is %d\n",my_id); my_customer = worker_table[my_id][1];//line 233 printf("Line 234\n"); int my id; The error happens

How to remove elements from dynamically allocated array?

北战南征 提交于 2019-12-13 02:25:09
问题 I have a dynamically allocated array : myRectangle lastRectanglesArray = new myRectangle[lastMaxLabel]; I would like to loop through all elements in this array and remove these that will meet my condition (e.g. too big rectangle). I have been thinking that I can loop through this array and get the number of elements that would satisfy my condition and then allocate a new array. But how can I 'transfer' these 'wanted' elements into my new array ? Just for the record: I cannot use STL