2017-04-06 51 views
1

我正在创建的程序不断发现无法解析的外部符号错误,我无法弄清楚自己出错的地方。无法找出无法解析的外部错误来自哪里

将出现的的错误是:

错误LNK1120:1周无法解析的外部

错误LNK2019:无法解析的外部符号 “公用:__thiscall链表::〜LinkedList的(无效)”(?? 1linkedList @ (__ Flist @@ YAXXZ)

任何帮助将不胜感激。本文地址:IT屋»如何使用动态atexit析构函数?

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; 

    do 
    { 
     menuSelect = NULL; 
     cout << "Please press one of the following options:"; 
     cout << "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"; 
     cout << "\n1. List all vehicles"; 
     cout << "\n2. Add a vehicle (Car or Van)"; 
     cout << "\n3. Remove a vehicle"; 
     cout << "\n4. Book a car"; 
     cout << "\n5. Book a van"; 
     cout << "\n6. Display a vehicle's details"; 
     cout << "\n7. List all cars currently not rented"; 
     cout << "\n8. List all 5-door cars"; 
     cout << "\n9. List all Ford vans currently rented"; 
     cout << "\n0. Quit"; 
     cout << "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n"; 
     cin >> menuSelect; 

     void addNode(); 
     void deleteNode(); 
     void getVehicles(); 

    switch (menuSelect) 
    { 
    case '1': 
     getVehicles(); //displays all vehicles in the list. 
     break; 

    case '2': 
     addNode();   //allows the user to add another vehicle. 
     break; 
    case '3': 
     deleteNode();  //allows the user to delete a vehicle. 
     break; 
    case '4': 
          //allows the user to book a car. 
     break;    
    case '5':   
          //allows the user to book a van. 
     break; 
    case '6':   
          //allows the user to select a vehicle and show it's details. 
     break; 
    case '7': 
          //lists all the vehicles that are currently not rented. 
     break; 
    case '8':    //lists all cars that are 5 door. 
     break; 

    case '9':    //lists all of the Ford vans that are currently rented. 
     break; 

    case '0': 
     system("pause"); 
     return 0; 

     break; 

    default: cout << "\n" << menuSelect << " is not a valid selection."; 

     cout << endl; 

    } 

} 
    while (menuSelect != 0); 
    return 0; 

} 

void addNode() 
{ 
     node* newNode = new node; 
     cout << "Is it a 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 the registration plate to be deleted: "; 
     cin >> searchData; 
    if (list.deleteNode(searchData)) 
     cout << "\nNode deleted. \n\n\n"; 

     cout << "\nThe registration plate is not in the 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 is empty\n"; 
     } 
     else 
      cout << "\tMake\tModel\tRegistration Number\tEngine Size\tRented?"; 


     do 
     { 
      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"; 
     } 
    } 
+1

'void linkedList :: insertNode(node * newNode)'的执行应该在Llist.cpp中而不是在vehicle.h中。 – mch

回答

1

的问题是在这条线:

~linkedList(); 

在这里,您析构函数声明为您linkedList,但就是你定义它的地方。

试着写

~linkedList() = default; 

或者,与旧标准c++

~linkedList() {}; 

或者只是完全删除此行 - 编译器会自动确定与你默认行为析构函数。

请注意,默认的析构函数不会删除任何指针成员,因此,在这种情况下,你将有一个内存泄漏(head不会被删除,释放)。这可以通过多种方式来解决,例如,使用std::unique_ptr<linkedList>而不是原始指针或者在析构函数体中明确写入delete head

+0

完成这项工作!谢谢 – bowlios

+0

@ bowlios如果有效,请将其标记为正确答案(正下方upvote downvote) – Elan

相关问题