Pb template liste generique
Je suis entrain d'essayer de creer une liste generique, mais j'ai quelques pb avec les templates.
Voila la classe:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#ifndef HEADER_LIST
#define HEADER_LIST
#include <iostream>
using namespace std;
// Classe liste
template <class T> class List {
private:
T m_val;
List<T> *m_next;
public:
List() ;
List(const List<T>&) ;
~List();
void addTail(T);
}... |
Le source qui va avec :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include "list.h"
//Methods canonic Copelian Form
template <class T>
List<T>::List(){
m_next = NULL;
}
template <class T>
List<T>::List(const List &l){
if (l.m_next == NULL) m_next = NULL;
else{
while (l.m_next != NULL){
addTail(l.m_val);
}
}
}
template <class T>
List<T>::~List(){
if (m_next != NULL) delete m_next;
}
template <class T>
void
List<T>::addTail(T element){
List<T> *newElem = new List;
newElem->m_next;
newElem->m_val = element;
m_next = newElem;
} |
Le main
Code:
1 2 3 4 5 6 7 8 9 10 11
|
#include "list.h"
int main(){
List<int> my_list;
my_list.addTail(2);
//my_list.addTail(1);
return 0;
} |
et a la compilation :
main.cpp:(.text+0x195): undefined reference to `List<int>::List()'
main.cpp:(.text+0x1a8): undefined reference to `List<int>::addTail(int)'
main.cpp:(.text+0x1b8): undefined reference to `List<int>::~List()'
main.cpp:(.text+0x1ce): undefined reference to `List<int>::~List()'
c'est la premiere fois que j'utilise les templates alors... J'aurais besoin d'aide :D
Merci d'avance