-2

I have a doubt, so I am asking here for some help. Thanks in advance.

I have defined a class that implements the file system basic function like this:

//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();
};

I am using doubly circular linked list in this.

Definitions of above functions

//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;
}
}

and main like this:

//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);
}   

it still gives me this error

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

Though i separated out all the functions still linker gives me error ,If someone notice something that I am doing wrong, please let me know. Also, let me know if anyone need more information. Thanks you very much

1 Answers1

1

First of all - declare destructor

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

And then - fix this:

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;

And finally - use std::list as a container instead of inventing your new container. If you need circular structure - use Boost::Circular buffer

Evgeniy
  • 2,481
  • 14
  • 24