"错误 LNK2019: 未解析的外部符号 "公共: __thiscall: 构造函数" 问题
"error LNK2019: unresolved external symbol "public: __thiscall : constructor" concern
我目前正在尝试用c++创建一个Module类和Student类的简单实现。这些课程将包含特定的模块和注册的个别学生。然而,每当我尝试创建Module或Student对象时,我似乎都无法绕过这个特定的错误消息。
这可能是我错过的一些简单的东西,但我已经上传了我的标题和下面的源文件。请帮帮我,这快把我逼疯了。提前谢谢。
学生.h:
#include "stdafx.h"
#include <string>
class Student {
public:
Student(std::string, std::string, int);
std::string getName() const { return name; }
std::string getDegree() const { return degree; }
int getLevel() const { return level; }
private:
std::string name;
std::string degree;
int level;
};
module.cpp:
// student.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "module.h"
#include <vector>
#include <iostream>
#include <string>
using namespace std;
void Module::enrol_student(Student studentY) {
students.push_back(studentY);
}
void Module::attendance_register() {
string nameX;
cout << "Attendance Register:n" << endl;
for (int i = 0; i < students.size(); i++) {
Student studentX = students.at(i);
nameX = studentX.getName();
cout << nameX << endl;
}
}
模块.h:
#include "stdafx.h"
#include "student.h"
#include <string>
#include <vector>
class Module {
public:
Module(std::string, std::string, std::vector<Student>);
std::string getModCode() { return modCode; }
std::string getModTitle() { return modTitle; }
void attendance_register();
void enrol_student(Student);
private:
std::string modCode;
std::string modTitle;
std::vector<Student> students;
};
testCode.cpp
// testCode.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
#include "module.h"
#include <vector>
#include <iostream>
#include <string>
using namespace std;
int main() {
//Initial Test Data
Student student1("Arthur Smith", "Computer Science", 1);
return 0;
}
您需要定义在类中声明的构造函数。在student.cpp中,你需要这样的东西:
Student::Student(std::string name, std::string degree, int level) : name(name), degree(degree), level(level)
{
}
这将使用提供的值初始化成员。
模块也是如此。
相关文章:
- 警告处理为错误这里有什么问题
- 最小硬币更换问题(自上而下方法)
- 为"adjacent"变量赋值时出现问题
- 我的神经网络不起作用 [XOR 问题]
- 在Ubuntu 16.04上安装Cilk时出现问题
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 编译包含字符串的代码时遇到问题
- 常量公共成员有什么问题?
- GCC 与 Clang 公共库问题
- 在主函数中调用公共函数时出现问题
- 如果私有虚拟函数被覆盖为派生类中的公共函数,那么问题是什么
- 在公共类中使用 C++ 字符* 时出现问题,无法访问 char 指针
- 公共/受保护/私有继承问题
- 使用向量查找公共元素的问题
- 简单的 Java 代码,在创建等效C++(私有静态成员和公共访问器方法)时遇到问题
- 我无法创建公共继承的构造函数有问题C++
- C++继承问题,无法调用基类中定义的公共函数
- 将类变量设为公共的问题
- 通信b/w两个线程在一个公共的数据结构.设计问题
- "错误 LNK2019: 未解析的外部符号 "公共: __thiscall: 构造函数" 问题