It's my first time asking for help here. When I try to compile the code I get the following errors. I'm using VS Code and sometimes, after a write more code, i get these errors. I have attached some screenshots with the two errors. I'm using C/C++: g++.exe when building my file.
The error in console:
Executing task: C/C++: g++.exe build active file
Starting build...cmd /c chcp 65001>nul && C:\msys64\ucrt64\bin\g++.exe -fdiagnostics-color=always -g "C:\Users\GLM21\Desktop\Mailfood - proiect\main.cpp" -o "C:\Users\GLM21\Desktop\Mailfood - proiect\main.exe"C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\GLM21\AppData\Local\Temp\ccvOXQCl.o: in function main': C:/Users/GLM21/Desktop/Mailfood - proiect/main.cpp:10:(.text+0x23d): undefined reference to
Client::getClient() const'C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/GLM21/Desktop/Mailfood - proiect/main.cpp:11:(.text+0x249): undefined reference to User::CreateAccount()' C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/GLM21/Desktop/Mailfood - proiect/main.cpp:12:(.text+0x255): undefined reference to
User::Login()'C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\GLM21\AppData\Local\Temp\ccvOXQCl.o: in function Client::Client(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': C:/Users/GLM21/Desktop/Mailfood - proiect/Client.h:9:(.text$_ZN6ClientC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_S7_S7_S7_S7_[_ZN6ClientC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_S7_S7_S7_S7_]+0x23): undefined reference to
User::User()'collect2.exe: error: ld returned 1 exit status
Build finished with error(s).
- The terminal process terminated with exit code: -1.
- Terminal will be reused by tasks, press any key to close it.
//main.cpp#include <iostream>#include "Client.h"using namespace std;int main(){ Client client("user123", "password", "John", "Doe", "123-456-7890", "123 Main St"); client.getClient(); client.CreateAccount(); client.Login(); return 0;}
//User.h#ifndef USER_H#define USER_H#include <string>class User {public: User(); User(const std::string&, const std::string&, const std::string&, const std::string&, const std::string&, const std::string&); void Login(); void CreateAccount();private: std::string username; std::string password; std::string Name; std::string LastName; std::string PhoneNumber; std::string Address;};#endif
//User.cpp#include "User.h"#include <string>#include <iostream> User::User(const std::string &username ,const std::string &password,const std::string &Name, const std::string &LastName, const std::string &PhoneNumber, const std::string &Adress ) :username(username),password(password), Name(Name), LastName(LastName), PhoneNumber(PhoneNumber), Address(Adress) {} void User::CreateAccount() { std::cout<<"Create your account: \n"; std::cout<<"Enter your username: \n"; std::cin>>username; std::cout<<"Enter your password: \n"; std::cin>>password; std::cout<<"Enter your name: \n"; std::cin>>Name; std::cout<<"Enter your last name: \n"; std::cin>>LastName; std::cout<<"Enter your phone number: \n"; std::cin>>PhoneNumber; std::cout<<"Enter your adress: \n"; std::cin>>Address; } void User::Login() { while(true) { std::cout<<"Enter your username: "; std::cin>>username; std::cout<<"Enter your password: "; std::cin>>password; if(this->username == username && this->password == password) { std::cout<<"Login succesful!"; // AppSystem(); break; } else std::cout<<"Invalid email or password \n"; } }
//Client.cpp#include "Client.h"#include <string>#include <iostream>Client::Client(const std::string &username ,const std::string &password, const std::string &Name, const std::string &LastName, const std::string &PhoneNumber, const std::string &Address ): User(username, password, Name, LastName, PhoneNumber, Address) {}void Client::getClient() const{ std::cout << "Client Information:\n"; std::cout << "Username: " << username << "\n"; std::cout << "Name: " << Name << "\n"; std::cout << "Last Name: " << LastName << "\n"; std::cout << "Phone Number: " << PhoneNumber << "\n"; std::cout << "Address: " << Address << "\n";}
//Client.h#ifndef CLIENT_H#define CLIENT_H#include <string>#include "User.h"class Client : public User{public: Client(const std::string& ,const std::string&, const std::string&, const std::string&, const std::string&, const std::string&):username(username),password(password), Name(Name), LastName(LastName), PhoneNumber(PhoneNumber), Address(Address) {} void getClient() const;private: std::string username; std::string password; std::string Name; std::string LastName; std::string PhoneNumber; std::string Address;};#endif
//tasks.json{"tasks": [ {"type": "cppbuild","label": "C/C++: g++.exe build active file","command": "C:\\msys64\\ucrt64\\bin\\g++.exe","args": ["-fdiagnostics-color=always","-g","${file}","-o","${fileDirname}\\${fileBasenameNoExtension}.exe" ],"options": {"cwd": "${fileDirname}" },"problemMatcher": ["$gcc" ],"group": {"kind": "build","isDefault": true },"detail": "Task generated by Debugger." } ],"version": "2.0.0"}
//settings.json{"C_Cpp_Runner.cCompilerPath": "gcc","C_Cpp_Runner.cppCompilerPath": "g++","C_Cpp_Runner.debuggerPath": "gdb","C_Cpp_Runner.cStandard": "","C_Cpp_Runner.cppStandard": "","C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvarsall.bat","C_Cpp_Runner.useMsvc": false,"C_Cpp_Runner.warnings": ["-Wall","-Wextra","-Wpedantic","-Wshadow","-Wformat=2","-Wcast-align","-Wconversion","-Wsign-conversion","-Wnull-dereference" ],"C_Cpp_Runner.msvcWarnings": ["/W4","/permissive-","/w14242","/w14287","/w14296","/w14311","/w14826","/w44062","/w44242","/w14905","/w14906","/w14263","/w44265","/w14928" ],"C_Cpp_Runner.enableWarnings": true,"C_Cpp_Runner.warningsAsError": false,"C_Cpp_Runner.compilerArgs": [],"C_Cpp_Runner.linkerArgs": [],"C_Cpp_Runner.includePaths": [],"C_Cpp_Runner.includeSearch": ["*","**/*" ],"C_Cpp_Runner.excludeSearch": ["**/build","**/build/**","**/.*","**/.*/**","**/.vscode","**/.vscode/**" ],"C_Cpp_Runner.useAddressSanitizer": false,"C_Cpp_Runner.useUndefinedSanitizer": false,"C_Cpp_Runner.useLeakSanitizer": false,"C_Cpp_Runner.showCompilationTime": false,"C_Cpp_Runner.useLinkTimeOptimization": false,"C_Cpp_Runner.msvcSecureNoWarnings": false}
{//launch.json"version": "0.2.0","configurations": [ {"name": "C/C++ Runner: Debug Session","type": "cppdbg","request": "launch","args": [],"stopAtEntry": false,"externalConsole": true,"cwd": "c:/Users/GLM21/Desktop/Mailfood - proiect","program": "c:/Users/GLM21/Desktop/Mailfood - proiect/build/Debug/outDebug","MIMode": "gdb","miDebuggerPath": "gdb","setupCommands": [ {"description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": true } ] } ]}
//c_cpp_properties.json{"configurations": [ {"name": "windows-gcc-x64","includePath": ["${workspaceFolder}/**" ],"compilerPath": "C:/msys64/ucrt64/bin/gcc.exe","cStandard": "${default}","cppStandard": "${default}","intelliSenseMode": "windows-gcc-x64","compilerArgs": ["" ] } ],"version": 4}