| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Syntax errors - Error C2100: illegal indirection
I am trying to perform an ascending sort on an array that is using pointers. I keep getting an illegal indirection error on the line below. (It's in sortArray function)
if (*(tests [index])< minValue) Any ideas? Here is my code: #include <iostream> using namespace std; //Function prototypes void sortArray(int *[], int); void showArray(int [], int); void calcaverage(); int average = 0; // To hold average test score int numTests; // To hold number of tests int main() { int *tests; // Dynamically allocated test score array. int total = 0; // Accumulator to calculate average int cntr; // Counter //********************************************* // Get the number of tests from user. * //********************************************* cout << "How many test scores do you have? "; cin >> numTests; //********************************************* //Dynamically allocate array to hold test scores. * //********************************************* tests = new int[numTests]; //******************************************** //Get test scores from user. * //********************************************* for(cntr = 0; cntr < numTests; cntr++) { cout << "Enter test score " << (cntr + 1 ) << ": "; cin >> tests[cntr]; total += tests[cntr]; { while(tests[cntr] < 0) { cout << "Enter a number greater than 0."; cin >> tests[cntr]; } } } return 0; } //********************************************* // Sort array in ascending order. * //********************************************* void sortArray(int *tests, int size) { int startScan, minIndex, minValue; for (startScan = 0; startScan < (size - 1); startScan++) { minIndex = startScan; minValue = tests[startScan]; for (int index = startScan +1; index < size; index++) { if (*(tests [index])< minValue) { minValue = tests[index]; minIndex = index; } } tests[minIndex] = tests[startScan]; tests[startScan] = minValue; } } //************************************************** ** // Display tests in ascending order. * //************************************************** ** void showArray(int tests, int numTests) { cout << "The sorted test scores are: \n"; for (int cntr = 0; cntr < numTests; cntr++) cout << tests[&cntr] <<" "; cout << endl; } //************************************************** * // Calculate Average * //************************************************** * void calcaverage(int total) { average = total / numTests; cout << "The average test score is " << average << endl; } //return 0; //} |
|
#2
|
||||
|
||||
|
Quote:
Note that the prototype talks about a function that takes an int**, while the one defined takes an int*. At link time, when it can't find a sortarray(int**,int) - the one declared by the time it chooses what to call from main() - it will give an error. The problem itself is this. int* tests; int a = tests[0]; // dereferenced int* is int ??? b = *a; // Illegal indirection, int is not a pointer Remove that extra *
__________________
Quote:
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Syntax errors - Error C2100: illegal indirection |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|