gpt4 book ai didi

c++ - C++中的编译错误(初级)

转载 作者:太空宇宙 更新时间:2023-11-04 15:18:21 24 4
gpt4 key购买 nike

<分区>

我是 C++ 的新手,我不明白我在这段代码中哪里错了。我接受这个错误:

ClCompile:
1> Student.cpp
1>Student.obj : error LNK2019: unresolved external symbol "public: void __thiscall Student::setExamGrade(int,int)" (?setExamGrade@Student@@QAEXHH@Z) referenced in function _main
1>c:\users\administrator\documents\visual studio 2010\Projects\LAB1\Debug\LAB1.exe : fatal error LNK1120: 1 unresolved externals
1>
1>Build FAILED.

你能帮帮我吗?代码在这里:

学生.h

#ifndef STUDENT_H
#define STUDENT_H

#include <string>
using namespace std;

class Student
{
private:
int ID;
string name;
int *exams;
public:
Student();
Student(int ID, string name);
void setExamGrade(int index, int grade);
int getOverallGrade();
void display();
};
#endif

学生.cpp

#include "Student.h"
#include <iostream>
using namespace std;

int total;
int count;
int average;
int exams[3];

void main() {
Student *s = new Student(123, "John");
s->setExamGrade(0, 80);
s->setExamGrade(1, 60);
s->setExamGrade(2, 95);
s->display();
delete s;
}

Student :: Student()
{
ID = 0;
name = "";
}

Student :: Student(int num, string text)
{
this->ID = num;
this->name = text;
}

void setExamGrade(int index, int grade)
{
exams[index] = grade;
total += exams[index];
count = index +1;
}

int getOverallGrade()
{
average = total/count;
return average;
}

void Student :: display()
{
cout << "ID:" << ID << "NAME:" << name << "GRADE:" << endl;
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com