| | |
Linking errors: 2 unresolved externals
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Dec 2008
Posts: 21
Reputation:
Solved Threads: 1
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
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++
Lemme explain hierarchy:
sLink inherits from Link
I use sLink to implement the List
and List to implement Hash Table
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?
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)
cl main.obj *.obj -libpath:..\LinkedListFolder"
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
- Jiberish Visual C++ Errors Un-Understandable (C++)
- error LNK2001: unresolved external... (C)
- linker errors in MSVC++ 2005 (C++)
- Annoying link errors (C++)
- Help! error LNK2001 & error LNK1120 (C++)
- Linking Error (C++)
- Winsnm Programming (C++)
- PLease can somebody help (C++)
- error LNK2001: unresolved external symbol (C++)
Other Threads in the C++ Forum
- Previous Thread: strings as input, substr and len
- Next Thread: Making a GUI in Unix?
Views: 514 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






