gpt4 book ai didi

每次添加类对象后都会出现 C++ LNK2019 错误

转载 作者:行者123 更新时间:2023-11-30 04:10:11 26 4
gpt4 key购买 nike

<分区>

我正在处理自己的双链表,每次在 Evidence.cpp 中添加类 DoubleList 的对象后,我都会收到 LNK2019 错误:未解析的外部符号。我会很高兴的每一个建议。这是我的代码:

StudentRecord.h

#pragma once
#include <string>
#include <iostream>
#include <algorithm>
#include "Student.h"
#include "DoubleList.h"
using namespace std;
using namespace SemestralWork;

class StudentRecord{
public:

DoubleList<Student> *List; //declared object (in StudentRecord.cpp is problem with that)

StudentRecord(void);
~StudentRecord(void);
Student &SearchStudent(const string &ID);
void addStudent(const Student &student, Student::Position position = Student::Position::LAST);
Student RemoveStudent(const string &ID);
void WriteAllStudents(void);
void Cancel(void);
};

StudentRecord.cpp(只是一部分)

#include "StdAfx.h"
#include "StudentRecord.h"
using namespace SemestralWork;

StudentRecord::StudentRecord(void)
{
List = new DoubleList<Student>(); // <---- here is first LNK2019 error
}

Student &StudentRecord::SearchStudent(const string &ID){
Student * SearchedStudent;
Student * EmptyStudent = NULL;

//********** down here are next 4 LNK2019 errors. ************

for(DoubleList<Student>::iterator it = List->begin(); it != List->end(); ++it){
if(ID == List->AccessActual().getID()){
SearchedStudent = &List->AccessActual();
return *SearchedStudent;
}
} // 5 unresolved externals
return *EmptyStudent;
}
//...

DoubleList(只是构造函数)

template<typename T>
DoubleList<T>::DoubleList(void){
NumberOfElements = 0;
First= NULL;
Last= NULL;
Actual= NULL;
}

Student.h

#pragma once
#include <string>
using namespace std;

class Student
{
private:
string firstName, lastName, ID;
public:
Student(string, string, string);
~Student(void);
string getFirstName();
string getLastName();
string getID();
enum Position{ FIRST, LAST, ACTUAL, PREVIOUS, NEXT};
};

编辑:此处的错误信息:

  • 错误 5 错误 LNK2019:未解析的外部符号“public: class Student & __thiscall SemestralWork::DoubleList::AccessActual(void)” (?AccessActual@?$DoubleList@VStudent@@@SemestralWork@@QAEAAVStudent@@XZ) 引用在函数“public: class Student & __thiscall StudentRecord::SearchStudent(class std::basic_string,class std::allocator > const &)” (?SearchStudent@StudentRecord@@QAEAAVStudent@@ABV?$basic_string@DU?$char_traits@ D@std@@V?$allocator@D@2@@std@@@Z)

(五个 LNK 错误之一)

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