首页 > 解决方案 > 未定义的引用在哪里?

问题描述

我有个问题!它显示了这个错误:

"C:\Users\User\AppData\Roaming\JetBrains\CLion 2018.2.4\bin\cmake\win\bin\cmake.exe" --build C:\Users\User\CLionProject\HospitalTest\cmake-build-debug --target HospitalTest -- -j 2
[ 50%] Linking CXX executable HospitalTest.exe
CMakeFiles\HospitalTest.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]: *** [CMakeFiles\HospitalTest.dir\build.make:85: HospitalTest.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:72: CMakeFiles/HospitalTest.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2: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;

标签: c++

解决方案


您可能已包含此文件,但尚未编写这些函数的实现。您需要实现所有功能才能编译程序。例如,函数的最小实现void DoNothing();是,

void DoNothing() {}

推荐阅读