它总是给出未定义的引用错误

It always gives undefined reference error

本文关键字:引用 错误 未定义      更新时间:2023-10-16

我正在编写代码,但给了我未定义的引用错误。错误如下:未定义的参考显示学生,未定义的adCourse 参考

  #include <iostream>
  #include "Course.h"
  #include "Student.h"
  #include "StudentReviewSystem.h"
 using namespace std;
  int main()
  {
    // create GradeBook object
    Course s( 201, "CS");
    cout << "name : " << s.courseName << endl;
    cout << "ID : " << s.courseID << endl;
    cout << "Enter student ID :" << endl;
    int ID;
    cin >> ID;
    cout << "Enter student name :" << endl;
    string name;
    cin >> name;
    s.addStudent(ID,name);
   //    cout << "You add the student with name: " << s.studentName << "  and ID : " << 
    cout << "Enter student ID :" << endl;
    int ID2;
   cin >> ID2;
   cout << "Enter student name :" << endl;
  string name2;
  cin >> name2;
    s.addStudent(ID2,name2);
    s.displayStudents();
   StudentReviewSystem ilknur;
    ilknur.addCourse(111,"HUM");
   cout << ilknur.courses[0].courseID;

 return 0; // indicate successful termination
 }

链接器告诉您,您的文件有一个无法解决的外部依赖项。

您可能需要将soruce代码的路径(StudentReviewSystem.c)包含到项目路径中。这就是你在《月食》中解决问题的方法。当您将文件添加到项目中时,VS会添加所需的一切。

每个cpp文件都必须经过编译和链接才能获得可执行文件。(如果没有使用外部库,至少应该这样做。)

如果这个提示没有帮助,请发布编译器和链接器命令或整个bild输出。