我无法解析LNK2019,LNK1120

时间:2014-11-11 01:33:56

标签: c++ linked-list linker-errors

我正在尝试链接类,但我在代码中找不到错误,给出的错误是错误

"错误LNK2019:未解析的外部符号" public:__ thiscall NumberList :: ~NumberList(void)" (?? 1NumberList @@ QAE @ XZ)在函数_main D:\ Fall 2014 \ C ++ ADV \ C ++ ADV \ Driver Program.obj"

中引用

然而,我正在查看我的驱动程序,我发现我正在正确地调用我的链接类,而且我不明白它是如何给我一个未解决的外部错误。如果有人看到我不是在看的东西,请告诉我。

**NumberList.h**

// Specification file for the NumberList class
#ifndef NUMBERLIST_H
#define NUMBERLIST_H

class NumberList
{
private:
  // Declare a structure for the list
  struct ListNode
 {
    double value;           // The value in this node
    struct ListNode *next;  // To point to the next node
 }; 

 ListNode *head;            // List head pointer

public:
 // Constructor
 NumberList()
    { head = NULL; }

 // Destructor
 ~NumberList();

 // Linked list operations
 void appendNode(double);
 void insertNode(double);
 void deleteNode(double);
 void displayList() const;
};
#endif


**NumberList.cpp**

        #include <iostream>
        #include "NumberList.h"
        using namespace std;

        void NumberList::appendNode(double num)
        {
            ListNode *newNode;  // To point to a new node
            ListNode *nodePtr;  // To move through the list 16     // Allocate a new node and store num there.
            newNode = new ListNode;
            newNode->value = num;
            newNode->next = NULL;

             // If there are no nodes in the list
             // make newNode the first node.
             if (!head)
                head = newNode;

            else  // Otherwise, insert newNode at end.
            {
                // Initialize nodePtr to head of list.
                nodePtr = head;

                // Find the last node in the list.
                while (nodePtr->next)
                nodePtr = nodePtr->next;

                // Insert newNode as the last node.
                nodePtr->next = newNode;
            }
        }

    void NumberList::displayList() const
    {
        ListNode *nodePtr;  // To move through the list

        // Position nodePtr at the head of the list.
        nodePtr = head;
        // While nodePtr points to a node, traverse
        // the list.
        while (nodePtr)
        {
            // Display the value in this node.
            cout << nodePtr->value << endl;
            // Move to the next node.
            nodePtr = nodePtr->next;
        }
    }


**Driver Program.cpp**// This is just to test out my list class

 // This program demonstrates the displayList member function.
      #include <iostream>
     #include "NumberList.h"
     using namespace std;
    int main()
    {
        // Define a NumberList object.
        NumberList list;
        // Append some values to the list.
         list.appendNode(2.5);
        list.appendNode(7.9);
        list.appendNode(12.6);
        // Display the values in the list.
        list.displayList();
         return 0;
    }

0 个答案:

没有答案