LNK2019未解析的外部符号?

时间:2016-10-15 14:27:43

标签: c++

我有疑问,所以我在这里要求一些帮助。提前谢谢。

我已经定义了一个实现文件系统基本功能的类,如下所示:

//Header.h
#include <iostream>
using namespace std;

typedef int BOOL;
#define TRUE 1
#define FALSE 0

typedef struct NODE
{
    struct NODE *prev;
    int data;
    struct NODE *next;
}NODE,*PNODE,**PPNODE;

class doubly_circular
{
   private:
           PNODE head;
           PNODE tail;

public:
       doubly_circular();
       ~doubly_circular();

       BOOL insertfirst(int);
       BOOL display();
       int count();
};

我在这里使用双循环链表。

上述功能的定义

//helper.cpp
doubly_circular::doubly_circular()
{
head=NULL;
tail=NULL;
}

BOOL doubly_circular::display()
{
PNODE temp=head;

if((head==NULL)&&(tail==NULL))
{
    return FALSE;
}

do
{
    cout<<temp->data<<endl;;
    temp=temp->next;
}while(tail->next!=temp);
return TRUE;
}

BOOL doubly_circular::insertfirst(int ino)
{
PNODE newN=NULL;
newN->prev=NULL;
newN->data=ino;
newN->next=NULL;

if((head==NULL)&&(tail==NULL))
{
    head=newN;
    tail=newN;
    tail->next=newN;
    head->prev=tail;
    return TRUE;
}
else
{
    newN->next=head;
    head->prev=newN;
    head=newN;
    head->prev=tail;
    tail->next=newN;
    return TRUE;
}
}

并且主要是这样的:

//main.cpp
int main()
{
doubly_circular obj1,obj2;

obj1.insertfirst(1);
obj1.insertfirst(101);
obj1.insertfirst(151);

obj1.display();

return 0;
}
doubly_circular::~doubly_circular()
{ 
    free(head);
    free(tail);
}   

它仍然给我这个错误

Error   1   error LNK2019: unresolved external symbol "public: __thiscall doubly_circular::~doubly_circular(void)" (??1doubly_circular@@QAE@XZ) referenced in function _main    I:\doublycircularLL\doublycircularLL\main.obj   doublycircularLL

虽然我将所有功能分开但链接器仍然给我错误,如果有人注意到我做错了,请告诉我。另外,如果有人需要更多信息,请与我们联系。非常感谢你

1 个答案:

答案 0 :(得分:1)

首先 - 声明析构函数

doubly_circular::~doubly_circular()
{ //destruction code here }

然后 - 解决这个问题:

PNODE newN=NULL; // this is incorrect, as you will not be able to assign data to a node
PNODE newN=new NODE; // construct new node
newN->prev=NULL;
newN->data=ino;
newN->next=NULL;

最后 - 使用std :: list作为容器而不是发明新容器。如果您需要循环结构 - 请使用Boost::Circular buffer

相关问题