tags:

views:

93

answers:

4

: error C2064: term does not evaluate to a function taking 1 arguments : error C2227: left of '->name' must point to class/struct/union/generic type

how do i fix this so this error doesn't happen

for(int index = 0; index < (numStudents); index++)
{
    if (student(index + 1)->score >= 90 )
        student(index + 1)->grade = 'A';
    else if (student(index + 1)->score >= 80 )
        student(index + 1)->grade = 'B';
    else if (student(index + 1)->score >= 70 )
        student(index + 1)->grade = 'C';
    else if (student(index + 1)->score >= 60 )
        student(index + 1)->grade = 'D';
    else 
        student(index + 1)->grade = 'F';
}

heres the structure:

struct StudentType
{
    string name;
    int score;
    char grade;
};

and here is the pointer : StudentType* student;

+5  A: 

My guess is that you need to do

student[index + 1]

instead of

student(index + 1)

You should really specify what is student so people can answer this question.

brickner
+1  A: 

From your comment answers it appears student is a pointer. In that case student(index + 1) is not valid syntax. I think you mean student[index + 1].

Further critique - 1 based arrays in C are bad form. Consider starting at 0 like everyone else in C

Stewart
+1  A: 

Is students a method/function or an array? Perhaps this is what you mean:

for (int index = 0; index < numStudents; index++) {
   // ensure that we don't go past the end of the student array
   if (index + 1 == numStudents) break;

   if (student[index + 1]->score >= 90) student[index + 1]->grade = 'A';
   else if (student[index + 1]->score >= 80) student[index + 1]->grade = 'B';
   else if (student[index + 1]->score >= 70) student[index + 1]->grade = 'C';
   else if (student[index + 1]->score >= 60) student[index + 1]->grade = 'D';
   else student[index + 1]->grade = 'F';
}

Though I don't understand why you are avoiding the first student (students[0]). You know arrays are zero-based, right? You could achieve the same effect without all of the 'index + 1' if you initialize the index variable to 1 instead of 0.

smountcastle
but it need to be in pointer arithmetic am i doing it completely wrong because i didn't even realize that it skipped 0
booby
So you mean that you must use:<pre>if ((student + index)->score >= 90) (student + index)->grade = 'A';</pre>I find that harder to read, but I guess if you *must* use pointer arithmetic there you go.
smountcastle
A: 

I'm pretty sure what it's trying to tell you is that the student function doesn't take just one argument. Since it couldn't actually call the function the second part of the error then tells you it can't be used to the left of ->

It's hard to say without more detail (specifically, what is student), but assuming student is a vector or array most likely you meant to say student[index + 1] instead of using the parentheses.

Mark B