![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Oct 2005
Location: Portugal
Posts: 53
Rep Power: 3
![]() |
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();
};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 ![]() |
|
|
|
|
|
#2 |
|
Programmer
Join Date: Oct 2005
Location: Portugal
Posts: 53
Rep Power: 3
![]() |
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? |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Jun 2005
Posts: 99
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Oct 2005
Location: Portugal
Posts: 53
Rep Power: 3
![]() |
Thanks for info
![]() |
|
|
|
|
|
#5 |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 630
Rep Power: 4
![]() |
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! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|