Linking errors: 2 unresolved externals

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Dec 2008
Posts: 21
Reputation: namehere05 is an unknown quantity at this point 
Solved Threads: 1
namehere05 namehere05 is offline Offline
Newbie Poster

Linking errors: 2 unresolved externals

 
0
  #1
Dec 8th, 2008
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++
  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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,758
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 283
Lerner Lerner is offline Offline
Posting Virtuoso

Re: Linking errors: 2 unresolved externals

 
0
  #2
Dec 8th, 2008
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.
Klatu Barada Nikto
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 21
Reputation: namehere05 is an unknown quantity at this point 
Solved Threads: 1
namehere05 namehere05 is offline Offline
Newbie Poster

Re: Linking errors: 2 unresolved externals

 
0
  #3
Dec 8th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 21
Reputation: namehere05 is an unknown quantity at this point 
Solved Threads: 1
namehere05 namehere05 is offline Offline
Newbie Poster

Re: Linking errors: 2 unresolved externals

 
0
  #4
Dec 10th, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 514 | Replies: 3
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC