Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 22nd, 2006, 8:17 AM   #1
-=PARADOX=-
Programmer
 
-=PARADOX=-'s Avatar
 
Join Date: Oct 2005
Location: Portugal
Posts: 53
Rep Power: 3 -=PARADOX=- is on a distinguished road
Linked List

Hi there,

I'm trying to make a linked list with templates

LinkedList.h
template <class Tipo>
class CLinkedList
{
	template <class Tipo>
	class No
	{
	public:
		const Tipo *p;
		No<Tipo> *next;
	};
	No<Tipo> *top;
	No<Tipo> *tail;
public:
	CLinkedList(void);
	virtual ~CLinkedList(void);
	virtual void add(const Tipo &);
	virtual bool remove(const Tipo &);
	virtual void showAll();
};
When I compile it it gives me the following errors:
error LNK2019: unresolved external symbol "public: virtual __thiscall CLinkedList<int>::~CLinkedList<int>(void)" (??1?$CLinkedList@H@@UAE@XZ) referenced in function _main

error LNK2019: unresolved external symbol "public: virtual void __thiscall CLinkedList<int>::showAll(void)" (?showAll@?$CLinkedList@H@@UAEXXZ) referenced in function _main

error LNK2019: unresolved external symbol "public: __thiscall CLinkedList<int>::CLinkedList<int>(void)" (??0?$CLinkedList@H@@QAE@XZ) referenced in function _main

Can someone help me with this?

thanks
-=PARADOX=- is offline   Reply With Quote
Old Jan 22nd, 2006, 9:53 AM   #2
-=PARADOX=-
Programmer
 
-=PARADOX=-'s Avatar
 
Join Date: Oct 2005
Location: Portugal
Posts: 53
Rep Power: 3 -=PARADOX=- is on a distinguished road
Well, it seems that C++ doesn't like templates in modules...

I've copy the definition code of the .h to the .cpp and everything works fine!

Can someone tell me why?
-=PARADOX=- is offline   Reply With Quote
Old Jan 22nd, 2006, 9:56 AM   #3
Animatronic
Programmer
 
Join Date: Jun 2005
Posts: 99
Rep Power: 4 Animatronic is on a distinguished road
Where are definitions for:

virtual ~CLinkedList(void);
virtual void add(const Tipo &);
virtual bool remove(const Tipo &);
virtual void showAll();

for most compilers template definitions need tobe available to every source file, so the function definitions should be present in the header file, either inside the class declaration or after.

Also are you sure you want to make them virtual, I cant see a reason to inherit off of the class.


No<Tipo> *top;
No<Tipo> *tail;

Shouldn't that be either head/tail or top/bottom .

The second template <class Tipo> in your class declaration is redundant.

const Tipo *p;

Are you sure you want to make that const, it would mean that you could only ever get const access to your data inside your linklist. Also why make it a pointer that will mean an extra call to malloc/new on insert, when you could just have the object itself.

edit:
You need to place the code in the headers for most compilers because the compiler neesd to generate the complete code for the class, in that source file, when it meets a instantiation of a template.
Animatronic is offline   Reply With Quote
Old Jan 22nd, 2006, 11:07 AM   #4
-=PARADOX=-
Programmer
 
-=PARADOX=-'s Avatar
 
Join Date: Oct 2005
Location: Portugal
Posts: 53
Rep Power: 3 -=PARADOX=- is on a distinguished road
Thanks for info
-=PARADOX=- is offline   Reply With Quote
Old Jan 22nd, 2006, 1:10 PM   #5
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 630
Rep Power: 4 Jessehk is on a distinguished road
Maybe it was just me, but I was unsure about the winking smilie. I didn't know what you were trying to imply.

Maybe just use a smilie-face smilie to show appreciation ( ).
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS!
Jessehk is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:12 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC