Classes Help
Sep 7, 2011 at 5:43am UTC
I have this piece of code and once i run it the same error message keeps recurring ... its been a while so I'm not sure what's the problem. A little help will be very much appreciated. Thanks in advance =)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
const int max_students = 15;
//class declarations
class StudentInfo {
public :
string first;
string last;
int score1;
int score2;
int score3;
int total_score;
string score_status;
};
class Student {
public :
StudentInfo info[];
};
//Function Prototypes
void readdata(Student [], int );
void printdata(Student [], int );
int main()
{
Student student[max_students];
int number;
readdata(student,number);
printdata(student,number);
return 0;
}
/* Function readdata()
*
*
*/
void readdata(Student student[], int number)
{
// open input file
ifstream infile("c:\\users\\MsDellie\\My Documents\\My_Programs\\Assgn#1_SATStudentInfo\\input.txt" );
// ifstream infile("con"); //un-comment for debugging
int count = 0; //initialize count
while (infile >> student[count].info.first)
{
infile >> student[count].info.last;
infile >> student[count].info.score1;
infile >> student[count].info.score2;
infile >> student[count].info.score3;
count++;
}
infile.close();
return ;
}
/* Function printdata()
*
*
*/
void printdata(Student student[],int number)
{
cout << endl << endl;
cout << "\t\tDatabase of Student SAT Scores" << endl << endl;
cout << "Scores\tStudent" << endl << endl;
for (int index = 0; index < max_students; index++)
{
cout << student[index].info.first;
cout << " " << student[index].info.last;
cout << "\t" << student[index].info.score1;
cout << "\t" << student[index].info.score2;
cout << "\t" << student[index].info.score3;
cout << endl;
index++;
}
return ;
}
The error message is this ::
|error: request for member 'first' in 'student->Student::info', which is of non-class type 'StudentInfo [0]'
Sep 7, 2011 at 5:50am UTC
1 2 3 4 5
//Line 20
class Student {
public :
StudentInfo info[]; //Why is this declared as an array? Try removing the "[]" (brackets...)
};
Sep 7, 2011 at 6:12am UTC
That did it, didn't even realize that was there. thanks a lot!!
Sep 7, 2011 at 6:13am UTC
No problem.
Topic archived. No new replies allowed.