Trying to pass an array
-
I am having some difficulty passing an array. If someone can shed some light here, I would appreciate it greatly.
to testCaseArray1[ ] int guessCount1 = 0; char choice1 = myChar; bool correctAnswer1 = myBool; -
I am having some difficulty passing an array. If someone can shed some light here, I would appreciate it greatly.
to testCaseArray1[ ] int guessCount1 = 0; char choice1 = myChar; bool correctAnswer1 = myBool;You should declare your function this way:
void testFunction(int, int, bool, int, int, int*, char);
There is another thing wrong in your program. This line:
to testCaseArray1[ ]You cannot declare an array this way (arraySize1 is not a constant). You need to dynamically allocate your array:
int* testCaseArray1 = new int[arraySize1];
And don't forget to delete it when you don't need it anymore. I would suggest that you take a look at container classes from the STL. It might be hard to understand for a beginner but it solves a lot of problems (memory management and so on).
Cédric Moonen Software developer
Charting control [v1.1] -
I am having some difficulty passing an array. If someone can shed some light here, I would appreciate it greatly.
to testCaseArray1[ ] int guessCount1 = 0; char choice1 = myChar; bool correctAnswer1 = myBool;OK, but where is your question? :O
ericelysia wrote:
int testCaseArray1[ arraySize1 ];
That won't work because you have to initialize your array with constant expressions. So the array should be defined like this:
int testCaseArray1[5];
If you want to initialize different size arrays you have to use new operand with pointer:int mySize; mySize=5; int *testCaseArray1=new int[mySize];
. When the array initialized with new operand is no longer needed you have to delete it with delete operand:delete [] testCaseArray1;