C++ 获得;需要一个标识符“;及;失踪'';在';之前'&引用;在具有结构的类中

C++ 获得;需要一个标识符“;及;失踪'';在';之前'&引用;在具有结构的类中,c++,class,struct,C++,Class,Struct,我想做一个成绩册程序。我正在为成绩册定义一个类的早期部分,它是结构的向量,每个结构都有一个字符串表示学生的名字和该学生成绩的向量。这是成绩册。h标题: // Creates a gradebook database that can be accessed and modified #ifndef GRADEBOOK_H #define GRADEBOOK_H #include <string> #include <vector> #include <iostre

我想做一个成绩册程序。我正在为成绩册定义一个类的早期部分,它是结构的向量,每个结构都有一个字符串表示学生的名字和该学生成绩的向量。这是成绩册。h标题:

// Creates a gradebook database that can be accessed and modified

#ifndef GRADEBOOK_H
#define GRADEBOOK_H
#include <string>
#include <vector>
#include <iostream>
#include <fstream>

using std::string;
using std::vector;
using std::cout;
using std::cin;
using std::endl;

class gradebook {
public:
    //--constructors
    gradebook();
    // post: An empty database is constructed

    //--modifiers
    void add_student(string name);
    // post: A new student is added who has the given name

    bool remove_student(string name);
    // post: If the name matches an existing student, that student is removed.
    // Otherwise, return false.

    void add_grades();
    // post: Adds grades input from the keyboard

    //--accessors
    void show_total_grade(string name);
    // post: Displays the cumulative grade for the student. If no student by
    // that name, display a message conveying such.

    void show_class_average();
    // post: Displays the average grade for the class.

    void show_student_grade(string name);
    // post: Displays grades for all assignemnts for the given student.

    void show_assignment_grade(int assignment);
    // post: Displays all the grades for the given assignment number.

    //--iterator functions

    struct book_entry
    {
        string my_name;
        vector<double> grades;

    book_entry(string name)
    {
        my_name = name;
        vector<double> grades;
    }

    void get_student(string name) {
        cout << my_name << ": ";
        for (auto &i : grades)
            cout << i << " ";
        cout << endl;

    }
};

private:
string my_student_name;
string my_assignment;
vector<book_entry> my_book;
double my_grade;
};

#endif
//创建可访问和修改的成绩册数据库
#ifndef成绩册
#定义成绩册
#包括
#包括
#包括
#包括
使用std::string;
使用std::vector;
使用std::cout;
使用std::cin;
使用std::endl;
班级成绩册{
公众:
//--建设者
成绩册();
//post:构建了一个空数据库
//--修饰语
void add_student(字符串名称);
//post:添加一个具有给定名称的新学生
bool remove_student(字符串名称);
//post:如果名称与现有学生匹配,则该学生将被删除。
//否则,返回false。
void add_grades();
//post:添加从键盘输入的分数
//--访问者
无效显示总等级(字符串名称);
//post:显示学生的累积成绩。如果没有学生
//那个名字,显示一条信息,传达这样的信息。
void show_class_average();
//post:显示班级的平均成绩。
无效显示学生成绩(字符串名称);
//post:显示给定学生所有作业的分数。
无效显示分配等级(整数分配);
//post:显示给定作业编号的所有等级。
//--迭代器函数
结构书项
{
把我的名字串起来;
病媒等级;
簿记项(字符串名称)
{
我的名字=名字;
病媒等级;
}
void get_student(字符串名称){
不能改变:

book_entry.get_student(string name);


另外,
book\u entry
应该是此范围内可用的对象。您显示的代码没有它,而您的第一个代码片段说它是一个类型而不是对象。

是的。这是一个问题。我做了更改,并在
name
下划线,表示它不是类型名称。至于您提出的第二个问题,如何解决我更改了它?这是这一行的正确修复方法。看看是否有编译器错误。您可能混淆了intellisense。如何修复它?它在最后一个大括号后有一个分号。我有两个分号:一个在结构的末尾,就在私有数据节之前,另一个在那之后,在
#endif
之前。
book_entry.get_student(string name);
book_entry.get_student(name);