Recently, I learned the C + + program video of dark horse. When I realized the employee management system based on polymorphism, I knocked the same code as the video, but I couldn’t compile it successfully by using vscode, and the following errors occurred:
[Employee_Management_System.cpp 2021-10-22 13:58:17.099]
,,C:\Users\AAE3~1\AppData\Local\Temp\cc7ZdaG7.o:Employee_Management_System.cpp:(.text+0x1b): undefined reference to `WorkerManager::WorkerManager()'
C:\Users\AAE3~1\AppData\Local\Temp\cc7ZdaG7.o:Employee_Management_System.cpp:(.text+0x27): undefined reference to `WorkerManager::Show_Menu()'
C:\Users\AAE3~1\AppData\Local\Temp\cc7ZdaG7.o:Employee_Management_System.cpp:(.text+0x44): undefined reference to `WorkerManager::~WorkerManager()'
C:\Users\AAE3~1\AppData\Local\Temp\cc7ZdaG7.o:Employee_Management_System.cpp:(.text+0x57): undefined reference to `WorkerManager::~WorkerManager()'
collect2.exe: error: ld returned 1 exit status
After querying many blogs, it is found that the causes and solutions of errors such as collect.exe: error: 1D returned 1 exit status are as follows
1. The last compiled program is not closed, that is, the black box still exists. Find it and close or restart the IDE
2. The program has no main function or the main function is misspelled
3. Running in vscode will not help you save the code. You need to save the code before running
4. The file name and file path may cause errors in some compilers
5. There is an undefined reference. This is the case for this error. When instantiating the classes of other files in the main function, you need to define the .H file and .Cpp file of other classes to solve the problem.
#include<iostream>
#include"workerManager.h"
#include"workerManager.cpp"