它总是给出未定义的引用错误
It always gives undefined reference error
我正在编写代码,但给了我未定义的引用错误。错误如下:未定义的参考显示学生,未定义的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输出。
相关文章:
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- C++引用错误
- 已定义函数时出现 G++ "未定义的引用"错误
- 链接 cmake 时出现未定义的引用错误
- 只有级联分类器会发出未定义的引用错误
- 2个模板化类的非模板友元函数未定义引用错误
- C/C++ 取消引用错误:在空检查之前取消引用
- 为什么我的C++代码无法编译,出现未定义的引用错误
- 我的代码中C++未定义的引用错误?
- 模板专用化会导致未定义的引用错误
- .cpp文件中未定义的引用错误
- c++ 中目录中文件的未定义引用错误
- Opencv4 使用 pkg-config 给出未定义的引用错误
- 使用Cygwin C++时出现未定义的引用错误,为什么我的文件没有链接?
- 共享指针取消引用错误
- 编译简单的多文件类程序时出现未定义的引用错误
- 模板函数产生未定义的引用错误
- 调用提取重加载器会产生对"运算符"的未定义引用错误>>
- 如何修复"未定义的引用"错误 opencv 和 g++
- 未定义的引用错误,我该怎么办?