Note that there are some explanatory texts on larger screens.

plurals
  1. POglobal variables and mulidimensional arrays outside of main in c++
    primarykey
    data
    text
    <p><strong>EDIT #1</strong> So I think my solution is to pass the class around through the functions, si then I have to get the size values in main and pass them into the class. So how would I create a multidimensional array within the class based on 2 int values? This is what I have, but I get the error "`ii' cannot appear in a constant-expression "</p> <pre><code>class tempHolder{ public: bool C1[col1][row1]; tempHolder(){ } tempHolder(int i, int ii){ int* C1 = new bool[i][ii]; } } </code></pre> <hr> <p>So my program has a multidimensional array, but I'm using global variables (which I know is bad style) to declare the size of the array. The problem is that I also pass this array to functions and I use it in a class, like the code below...</p> <pre><code>#include &lt;iostream&gt; using namespace std; const int row1 = 12; const int col1 = 32; class tempHolder{ public: bool C1[col1][row1]; void operator=(bool C2[col1][row1]){ for(int i=0;i&lt;row1;i++) for(int ii=0;ii&lt;col1;ii++) C1[i][ii] = C2[i][ii]; } }; void printTable(bool CC[][row1], int, bool); int main(int argc, char *argv[]) { col1=5; //error bool C1[col1][row1]; </code></pre> <p>So I want to be able to change the values of row1 and col1 right at the beginning of main, which would then change the array size for the entire program. If I declare the global variables like above, then the program compiles, but since they are constants, I won't be able to change them. I can't use a #define because those are not changeable at all. So what can I do to resize the array for the entire program?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload