what I mean by undefined error is because I don't know what the error is about. :P, actually it's because the error not from the code itself, but it's about a compiler that can't defined some sort of file...

btw, as title said, the error is from the code in Accelerated C++ book, you can see attachment that I included to analyze the error that I had.

and here the code, [from main.cpp]

#include <algorithm>
#include <iomanip>
#include <ios>
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>

#include "grade.h"
#include "Student_info.h"

using std::cin;                     using std::setprecision;
using std::cout;                    using std::sort;
using std::domain_error;            using std::streamsize;
using std::endl;                    using std::string;
using std::max;                     using std::vector;

int main()
{
    vector<Student_info> students;
    Student_info record;
    string::size_type maxlen = 0;       // the length of the longest name

    // read and store all the students data.
    // Invariant:  students contains all the student records read so far
    //   maxlen contains the length of the longest name in students
    while (read(cin, record)) {
        // find length of longest name
        maxlen = max(maxlen, record.name.size());
        students.push_back(record);
    }

    // alphabetize the student records
    sort(students.begin(), students.end(), compare);

    // write the names and grades
    for (vector<Student_info>::size_type i = 0;
         i != students.size(); ++i) {

        // write the name, padded on the right to maxlen + 1 characters
        cout << students[i].name
             << string(maxlen + 1 - students[i].name.size(), ' ');

        // compute and write the grade
        try {
            double final_grade = grade(students[i]);
            streamsize prec = cout.precision();
            cout << setprecision(3) << final_grade
                 << setprecision(prec);
        } catch (domain_error e) {
            cout << e.what();
        }
        cout << endl;
    }
    return 0;
}

and this one from one of the header [grade.h]

#ifndef GRADE_H_INCLUDED
#define GRADE_H_INCLUDED

// grade.h
#include <vector>
#include "Student_info.h"

double grade(double, double, double);
double grade(double, double, const std::vector<double>&);
double grade(const Student_info&);

#endif // GRADE_H_INCLUDED

this one too [Student_info.h]

#ifndef STUDENT_INFO_H_INCLUDED
#define STUDENT_INFO_H_INCLUDED

// Student_info.h header file
#include <iostream>
#include <string>
#include <vector>

struct Student_info {
	std::string name;
	double midterm, final;
	std::vector<double> homework;
};

bool compare(const Student_info&, const Student_info&);
std::istream& read(std::istream&, Student_info&);
std::istream& read_hw(std::istream&, std::vector<double>&);


#endif // STUDENT_INFO_H_INCLUDED

that's all, thnx for reading, hope anyone bother to give a hand...

Recommended Answers

All 2 Replies

Where is grade() defined? It's referenced in grade.h, but I don't see a definition. Same goes for some of your other functions.

The problem file, grade.h.gch , is a GCC precompiled header. Did this file come with the example code? If it did, try deleting it and compiling again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.