未定义的引用在哪里

Where is the undefined reference?

本文关键字:在哪里 引用 未定义      更新时间:2023-10-16

我有问题!显示此错误:

"C:UsersUserAppDataRoamingJetBrainsCLion 2018.2.4bincmakewinbincmake.exe" --build C:UsersUserCLionProjectHospitalTestcmake-build-debug --target HospitalTest -- -j 2
[ 50%] Linking CXX executable HospitalTest.exe
CMakeFilesHospitalTest.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/User/CLionProject/HospitalTest/main.cpp:9: undefined reference to `CHospitalWard::CHospitalWard()'
C:/Users/User/CLionProject/HospitalTest/main.cpp:23: undefined reference to `CHospitalWard::OnAdd()'
C:/Users/User/CLionProject/HospitalTest/main.cpp:24: undefined reference to `CHospitalWard::OnDelRegNum()'
C:/Users/User/CLionProject/HospitalTest/main.cpp:25: undefined reference to `CHospitalWard::OldestPatient()'
C:/Users/User/CLionProject/HospitalTest/main.cpp:26: undefined reference to `CHospitalWard::OnPrint()'
C:/Users/User/CLionProject/HospitalTest/main.cpp:27: undefined reference to `CHospitalWard::IsInRegNum()'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFilesHospitalTest.dirbuild.make:85: HospitalTest.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFilesMakefile2:72: CMakeFiles/HospitalTest.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFilesMakefile2:84: CMakeFiles/HospitalTest.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:117: HospitalTest] Error 2

代码:

///////////////////////////////
#pragma once
#include "Patient.h"
#include <string>
using namespace std;
class CHospitalWard
{
private:
string m_name;
int m_br;
CPatient *m;
public:
CHospitalWard();
CHospitalWard(string, int);
~CHospitalWard(){delete []m;}
void OnAdd();
void OnDelRegNum();
void OnPrint();
int IsInRegNum();
void OldestPatient();
string name_access() {return m_name;}
int br_access() {return m_br;}
};

有这样的声明:

cout<<"Generating..."<<endl;
CHospitalWard f;
int c;
string s;

您可能已经包含了这个文件,但还没有为这些函数编写实现。为了编译程序,您需要实现所有函数。例如,函数void DoNothing();的最小实现是

void DoNothing() {}