Message-ID: <39BAE868.B8948FF7@operamail.com> From: Sahab Yazdani Organization: PheonixSoft Inc. X-Mailer: Mozilla 4.7 [en] (Win98; I) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: template header files Content-Type: multipart/mixed; boundary="------------5CAFDB692585048271662E56" Lines: 176 Date: Sat, 09 Sep 2000 21:48:24 -0400 NNTP-Posting-Host: 149.99.126.25 X-Complaints-To: abuse AT sprint DOT ca X-Trace: newscontent-01.sprint.ca 968551017 149.99.126.25 (Sat, 09 Sep 2000 21:56:57 EDT) NNTP-Posting-Date: Sat, 09 Sep 2000 21:56:57 EDT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com This is a multi-part message in MIME format. --------------5CAFDB692585048271662E56 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit hello i have written my own linked list template file and now want to use it as a library (you know in different executables, etc). the problem is that for every time that I write: LinkedList bob; the linker returns "undefined reference to LinkedList" and refuses to actually compile the code. i have included as attachment the header file for the linked list, the actual code and a short sample program using this library (which obviously doesn't work..) thank you in advance for any help you may provide. PS. Sorry if this isn't a DJGPP specific question... -- *********************************************************** * Sahab Yazdani * "Remember, I'm the monkey and you're the* * Thornhill S.S * cheese grater. So no messing around." * *********************************************************** * http://pheonixsoft.virtualave.net/ * *********************************************************** --------------5CAFDB692585048271662E56 Content-Type: text/plain; charset=us-ascii; name="test.cc" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="test.cc" #include "linklist.h" void main() { LinkedList *test = new LinkedList(); test->Add( 50 ); delete test; } --------------5CAFDB692585048271662E56 Content-Type: text/plain; charset=us-ascii; name="linklist.h" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="linklist.h" #ifndef LIST_H #define LIST_H template class LinkedListObject { public: T object; LinkedListObject *next; }; template class LinkedList { private: int entities; LinkedListObject *first; public: LinkedList(); ~LinkedList(); void Add( T object ); void Delete( int entity ); T Get( int entity ); void Set( int entity, T newValue ); int GetEntities(); }; #endif --------------5CAFDB692585048271662E56 Content-Type: text/plain; charset=us-ascii; name="linklist.cc" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="linklist.cc" #include #include "linklist.h" template LinkedList::LinkedList() { first=NULL; entities=0; } template LinkedList::~LinkedList() { LinkedListObject *counter; LinkedListObject *last; last = first; for ( counter=first->next;counter!=NULL;counter=counter->next) delete last; } template void LinkedList::Add( T object ) { LinkedListObject *newObject; newObject = new LinkedListObject(); newObject->object = object; newObject->next=first; first = newObject; entities++; } template void LinkedList::Delete( int entity ) { LinkedListObject *spider; LinkedListObject *last; int counter=0; spider=first; while (counter!=entity) { last=spider; spider=spider->next; counter++; } last->next = spider->next; entities--; delete spider; } template T LinkedList::Get( int entity ) { LinkedListObject *spider; int counter=0; spider=first; while (counter!=entity) { spider=spider->next; counter++; } return spider->object; } template void LinkedList::Set( int entity, T newValue ) { LinkedListObject *spider; int counter=0; spider=first; while (counter!=entity) { spider=spider->next; counter++; } spider->object = newValue; } template int LinkedList::GetEntities() { return entities; } --------------5CAFDB692585048271662E56--