Mail Archives: djgpp/2000/09/09/22:01:57
Message-ID: | <39BAE868.B8948FF7@operamail.com>
|
From: | Sahab Yazdani <sahaby AT operamail DOT com>
|
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
|
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<foo> bob;
the linker returns "undefined reference to LinkedList<foo>" 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<int> *test = new LinkedList<int>();
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 T>
class LinkedListObject {
public:
T object;
LinkedListObject<T> *next;
};
template<class T>
class LinkedList {
private:
int entities;
LinkedListObject<T> *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 <stdlib.h>
#include "linklist.h"
template<class T>
LinkedList<T>::LinkedList() {
first=NULL;
entities=0;
}
template<class T>
LinkedList<T>::~LinkedList() {
LinkedListObject<T> *counter;
LinkedListObject<T> *last;
last = first;
for ( counter=first->next;counter!=NULL;counter=counter->next)
delete last;
}
template<class T>
void LinkedList<T>::Add( T object ) {
LinkedListObject<T> *newObject;
newObject = new LinkedListObject<T>();
newObject->object = object;
newObject->next=first;
first = newObject;
entities++;
}
template<class T>
void LinkedList<T>::Delete( int entity ) {
LinkedListObject<T> *spider;
LinkedListObject<T> *last;
int counter=0;
spider=first;
while (counter!=entity) {
last=spider;
spider=spider->next;
counter++;
}
last->next = spider->next;
entities--;
delete spider;
}
template<class T>
T LinkedList<T>::Get( int entity ) {
LinkedListObject<T> *spider;
int counter=0;
spider=first;
while (counter!=entity) {
spider=spider->next;
counter++;
}
return spider->object;
}
template<class T>
void LinkedList<T>::Set( int entity, T newValue ) {
LinkedListObject<T> *spider;
int counter=0;
spider=first;
while (counter!=entity) {
spider=spider->next;
counter++;
}
spider->object = newValue;
}
template<class T>
int LinkedList<T>::GetEntities() {
return entities;
}
--------------5CAFDB692585048271662E56--
- Raw text -