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

时间:2013-11-20 19:59:19

标签: c++

我正在编写代码但是给了我未定义的引用错误。这是错误:undefined ref。哟展示学生,未定义参考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
 }

2 个答案:

答案 0 :(得分:0)

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

如果该提示无效,请发布您的编译器和链接器命令或整个bild输出。

答案 1 :(得分:0)

链接器告诉您文件具有无法解析的外部依赖关系。

您可能需要在项目路径中包含soruce代码(StudentReviewSystem.c)的路径。这就是你在Eclipe中解决它的方法。当您向项目添加文件时,VS会添加所需的一切。

相关问题