c++ - Can't figure where the unresolved external error is coming from -


the program i'm creating keeps coming unresolved external symbol error , can't figure out going wrong.

the errors coming are:

error lnk1120: 1 unresolved externals

error lnk2019: unresolved external symbol "public: __thiscall linkedlist::~linkedlist(void)" (??1linkedlist@@qae@xz) referenced in function "void __cdecl `dynamic atexit destructor 'list''(void)" (??__flist@@yaxxz)

any appreciated.

source.cpp

#include <iostream> #include <string> #include "llist.h" #include "vehicle.h" #include "windows.h" #include <iomanip>  using namespace std;  linkedlist list;  int main() {     char menuselect;          {         menuselect = null;         cout << "please press 1 of following options:";         cout << "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-";         cout << "\n1. list vehicles";         cout << "\n2. add vehicle (car or van)";         cout << "\n3. remove vehicle";         cout << "\n4. book car";         cout << "\n5. book van";         cout << "\n6. display vehicle's details";         cout << "\n7. list cars not rented";         cout << "\n8. list 5-door cars";         cout << "\n9. list ford vans rented";         cout << "\n0. quit";         cout << "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n";         cin >> menuselect;          void addnode();         void deletenode();         void getvehicles();      switch (menuselect)     {     case '1':         getvehicles();  //displays vehicles in list.           break;      case '2':         addnode();          //allows user add vehicle.         break;     case '3':         deletenode();       //allows user delete vehicle.          break;     case '4':                             //allows user book car.         break;                   case '5':                                        //allows user book van.         break;     case '6':                                        //allows user select vehicle , show it's details.         break;     case '7':                             //lists vehicles not rented.         break;     case '8':               //lists cars 5 door.          break;      case '9':               //lists of ford vans rented.          break;      case '0':         system("pause");         return 0;          break;      default: cout << "\n" << menuselect << " not valid selection.";          cout << endl;      }  }     while (menuselect != 0);     return 0;  }  void addnode() {         node* newnode = new node;         cout << "is car or van?: \n";         cin >> newnode->make;          cout << "\nenter model: \n";         cin >> newnode->model;          cout << "\nenter engine size: \n";         cin >> newnode->engine;          cout << "\nenter registration number: \n ";         cin >> newnode->registration;          list.insertnode(newnode);  }  void deletenode() {     char searchdata;         cout << "enter registration plate deleted: ";         cin >> searchdata;     if (list.deletenode(searchdata))         cout << "\nnode deleted. \n\n\n";          cout << "\nthe registration plate not in list\n\n"; }  void getvehicles() {     string searchdata;     list.displaylist();  } 

llist.h

#include <string> #include "vehicle.h" #include "windows.h" #include <iostream>   using namespace std;   struct node {     int registration;     double engine;     string model;     string make;     node* nextnode;     int data; };  class linkedlist { private:     node* head;  public:     linkedlist() { head = null; }     void insertnode(node*);     void searchnode(int);     bool deletenode(int deletevehicle);     void displaylist();     ~linkedlist();  }; 

llist.cpp

#include <iostream> #include "windows.h" #include <string> #include "llist.h" #include "vehicle.h" #include <iomanip> using namespace std; 

vehicle.h

#pragma once #include <string> #include "windows.h" //#include "llist.h" template<class registration = int>   class vehicle { public:      typedef enum { car, van } vehicletype;  protected:     vehicletype make;     char model;     bool rent;     double enginesize;     int registration;    public:      vehicle(vehicletype make) : model(""), registration(reg), enginesize(engine), make(make), rented(false){}     char getmakemodel();     bool getrented;     bool setrented(bool rent);     int getenginesize();     int getregistration();     ~vehicle();      void listvehicle();     void removevehicle(int deletevehicle);     void addvehicle();     void bookvehicle();     void displaydetails(int registration);     void listnonrented();     void listfivedoor();     void listrentedfordvan(); };          void linkedlist::insertnode(node* newnode)     {         newnode->nextnode = head;         head = newnode;     }      bool linkedlist::deletenode(int deletevehicle)     {         node* beforenode = head;         node* thisnode = head;         bool found = false;           while ((thisnode != null) && !found)         {             if (thisnode->data == deletevehicle)                 found = true;             else             {                 beforenode = thisnode;                 thisnode = thisnode->nextnode;             }         }           if (found)         {             if (thisnode == head)             {                 node* oldhead = head;                 head = head->nextnode;                 delete oldhead;             }             else             {                 beforenode->nextnode = thisnode->nextnode;                 delete thisnode;             }             return true;             }         return false;            }      void linkedlist:: displaylist()     {          node* thisnode = head;          if (head == null)         {             cout << "\nthe list empty\n";         }         else             cout << "\tmake\tmodel\tregistration number\tengine size\trented?";                   {             cout << setw(30) << left << thisnode->make;             cout << setw(25) << left << thisnode->model;             cout << setw(20) << left << thisnode->registration;             cout << setw(15) << left << thisnode->engine;             //cout << setw(10) << left << thisnode->rented;           } while (thisnode != null);         {             cout << "\n\n";         }     } 

the problem in line:

~linkedlist(); 

here declared destructor linkedlist, there's no place defined it.

try writing

~linkedlist() = default; 

or, older c++ standard,

~linkedlist() {}; 

or remove line - compiler define destructor default behavior you, automatically.

please note default destructor not delete pointer members, so, in case, have memory leak (head not deleted , deallocated). may fixed in number of ways, example, using std::unique_ptr<linkedlist> instead of raw pointers or explicitly writing delete head in destructor body.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -