0
votes

I've been working on a Doubly Linked List code and I'm unable to locate what is causing an error every time I attempt compiling. The error being thrown is

main.obj : error LNK2019: unresolved external symbol "public: __thiscall DoublyList::DoublyList(void)" (??0?$DoublyList@H@@QAE@XZ) referenced in function >_main 1>Doubly List.exe : fatal error LNK1120: 1 unresolved externals

DoublyList.h -> http://pastebin.com/5wbeKksv
DoublyListNode.h and main.cpp -> http://pastebin.com/vVdGpgaW

4
Note that this isn't a compiler error, but rather a linker error.mergeconflict

4 Answers

2
votes

You declare but don't define DoublyList default constructor. Same goes for its destructor.

0
votes

You have declared a constructor for DoublyList but not defined it. Add a {} after your DoublyList() and see if it works take off the ; too.

0
votes

You've defined the copy constructor, but forgotten to define the default constructor:

template< class T >
DoublyList< T > :: DoublyList() : head(NULL), size( 0 )
{
    // empty body
} // end DoublyList
0
votes

Not related to your question, and I know this isn't the codereview section, but here are some of my thoughts.

In your insert function

DoublyListNode < T > *newPtr = new DoublyListNode< T >(tempData);
newPtr->nextPtr = newPtr->prePtr = NULL;
if(newPtr == NULL)
{
     cout << "Insert cannot allocate memory\n";
} //end if

should be

DoublyListNode < T > *newPtr = new DoublyListNode< T >(tempData);
if(newPtr == NULL)
{
     cout << "Insert cannot allocate memory\n";
}else{
     newPtr->nextPtr = newPtr->prePtr = NULL;
     // rest of code

Also, in your find function

DoublyListNode< T > *currentPtr = head;
for(int i = 1; i < index; i++)
{
     currentPtr = currentPtr->nextPtr;
} // end for

should be

DoublyListNode< T > *currentPtr = head;
for(int i = 1; currentPtr && (i < index); i++)
{
     currentPtr = currentPtr->nextPtr;
} // end for

Also, since you are using C++, consider making your indexes 0-based (looking at your code they are atm 1-based)