943,633 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 921
  • C++ RSS
Dec 8th, 2008
0

Linking errors: 2 unresolved externals

Expand Post »
Im trying to make this Hash Table to work, but I get these errors on linking time

main.obj : error LNK2019: unresolved external symbol "public: __thiscall List::~List(void)" (??1List@@QAE@XZ) referenced in function "public: __thiscall HTable::~HTable(void)" (??1HTable@@QAE@XZ)

StringTable.obj : error LNK2001: unresolved external symbol "public: __thiscall List::~List(void)" (??1List@@QAE@XZ)

HashTable.obj : error LNK2019: unresolved external symbol "public: void __thiscall List::Add(int)" (?Add@List@@QAEXH@Z) referenced in function "public: void __thiscall HTable::Add(char const *,int)" (?Add@HTable@@QAEXPBDH@Z)

main.exe : fatal error LNK1120: 2 unresolved externals

this is the body of those functions
//HashTable.cpp
List const & HTable::Find (char const * str) const
{
int i = hash (str);
return _aList [i];
}

void HTable::Add (char const * str, int id)
{
int i = hash (str);
_aList[i].Add (id);
}

They use class List wich I have included on header file HashTable.h. List.h and List.obj are in another folder "..\LinkedListFolder" and the other obj are inside main folder so I issued:


//Im using Visual C++
C++ Syntax (Toggle Plain Text)
  1. cl main.obj *.obj -libpath:..\LinkedListFolder"
  2.  

Lemme explain hierarchy:
sLink inherits from Link
I use sLink to implement the List
and List to implement Hash Table

//link.h
class Link
{
public:
Link (int id): _id (id) {}
virtual ~Link();
int Id () const { return _id; }
private:
int _id;
};


//sLink.h
#include "Link.h"
class sLink : public Link
{
public:
  sLink (sLink* pNext, int id): Link(id), _pNext (pNext)   {}
  sLink * Next () const { return _pNext; }
private:
  sLink * _pNext;
};

List.h
#include "sLink.h"
class List
{
public:
List (): _pHead (NULL){}
~List ();
void Add ( int id );
sLink const * GetHead () const { return _pHead; }
private:
sLink * _pHead;
};


//List.cpp
#include "sList.h"

List::~List ()
{
// free the list
while ( _pHead != NULL )
{
sLink* pLink = _pHead;
_pHead = _pHead->Next(); // unlink pLink
delete pLink;
}
}

void List::Add ( int id )
{
// add in front of the list
sLink * pLink = new sLink (_pHead, id);
_pHead = pLink;
}

//HashTable.h
#include "sList.h"

const int sizeHTable = 127;

// Hash table of strings
class HTable
{
public:
List const & Find (char const * str) const;// return a short list of candidates
void Add (char const * str, int id);// add another string->id mapping
private:
int hash (char const * str) const;  // the hashing function
List _aList [sizeHTable]; // an array of (short) lists
};

BTW Could you clarify me if in fact destructor of sList on cpp is called or is it assuming empty constructor due to declaration of destructor on header file.

So why the linking errors?
Last edited by namehere05; Dec 8th, 2008 at 1:40 pm.
Similar Threads
Reputation Points: 11
Solved Threads: 1
Light Poster
namehere05 is offline Offline
25 posts
since Dec 2008
Dec 8th, 2008
0

Re: Linking errors: 2 unresolved externals

Follow your includes. HashTable.h includes sList.h, but I don't see an sList.h. I do see a List.h, though. Same in List.cpp, you include sList.h instead of List.h.
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005
Dec 8th, 2008
0

Re: Linking errors: 2 unresolved externals

yea sry It was a typo when I was making thread I didnt cut and paste documents name the correct name for List.h is sList.h
Reputation Points: 11
Solved Threads: 1
Light Poster
namehere05 is offline Offline
25 posts
since Dec 2008
Dec 10th, 2008
0

Re: Linking errors: 2 unresolved externals

This is an excersice from the book "C++ In action" you can google for the book title and it will take you to its official site where you can find the book also the source Code, I will look at it to see my mistake.
Reputation Points: 11
Solved Threads: 1
Light Poster
namehere05 is offline Offline
25 posts
since Dec 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: strings as input, substr and len
Next Thread in C++ Forum Timeline: Making a GUI in Unix?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC