I am getting a weird error message that says"invalid types 'int[int]' for array subscript", I am trying to make a function that prints out a multidimensional array. It's probably just a careless mistake but I'm am new to C++ and only 13 years old: here is the code:
OK, I did that and it said that the integers 'rows' and 'columns' were not declared in this scope, so right above that I declared them. then it gave me this message
C:\Users\Eamon\Documents\C++ programs\test\arrayf.h|19|error: array bound is not an integer constant|
||=== Build finished: 1 errors, 0 warnings ===|
I don't what this is and I have never seen it before
here is my code:
I'm sorry if I'm not very clear. It's not important what you call your array or how you create it. The important thing is that the size is rows * columns.
Sorry if I'm not clear. It's not important what you name the array or how it's created. The important thing is that it has rows * columns elements. You decide what rows and columns is for your array. If you don't dynamically allocate your array you have to use a constant size. rows and columns are not constants so that's why you got an error.
Ok I kind of see where your getting at now. so I am assuming that a constant size is just a value like: int a = 9. (please correct me if I am wrong.) If that is the case then a constant size will not work for me because the purpose of the function is to print out arrays of all different sizes, so that means I have to dynamically allocate my array, Could you please show me how to do that?
Ok that makes sense, but it is still asking for a destructor or type conversion,
I still don't understand why or how I can have that,
again probably just a careless mistake.
Here is the error:
C:\Users\Eamon\Documents\C++ programs\test\arrayf.h|18|error: expected constructor, destructor, or type conversion before '(' token|
C:\Users\Eamon\Documents\C++ programs\test\arrayf.h|23|error: expected constructor, destructor, or type conversion before '(' token|
||=== Build finished: 2 errors, 0 warnings ===|
How do you call the functions? This could be the reason!
In the main you declare your array and call the functions. It seems to me you do s.th. like printArray(myarray[0], 5); instead of printArray(myarray, 5);
You maybe want to put the code of the functions into the .cpp-file and just leave the prototypes in the header.