|
|
|
|
Bonjour,
j'ai crée une classe "Tableau" avec un constructeur avec et sans argument, lorsque j'appel un constructeur dans main , il m'affiche cet erreur:
[Linker error] undefined reference to `Tableau<int>::Tableau(int)'
#include <cstdlib>
#include <iostream>
using namespace std;
template <class T>
class Tableau{
protected:
T *tab;
int dim;
public:
Tableau();
Tableau(int);
void affiche();
};
template <class T>
Tableau<T>::Tableau(){
dim=0;
tab=NULL;
}
template <class T>
Tableau<T>::Tableau(int n):dim(n){
tab=new T[dim];
}
template <class T>
void Tableau<T>::affiche(){
for(int i=0;i<dim;i++){
cout<<tab[i]<<endl;
}
}
#include <cstdlib>
#include <iostream>
#include "tableau.h"
using namespace std;
int main(int argc, char *argv[])
{
Tableau<int> t(2);
system("PAUSE");
return EXIT_SUCCESS;
}
Configuration: Windows XP Safari 530.5
Voila j'ai ajouté un destructeur mais toujours le meme probleme:
#include <cstdlib>
#include <iostream>
using namespace std;
template <class T>
class Tableau{
protected:
T *tab;
int dim;
public:
Tableau();
Tableau(int);
void affiche();
~Tableau();
};
template <class T>
Tableau<T>::Tableau(){
dim=0;
tab=NULL;
}
template <class T>
Tableau<T>::Tableau(int n):dim(n){
tab=new T[dim];
}
template <class T>
void Tableau<T>::affiche(){
for(int i=0;i<dim;i++){
cout<<tab[i]<<endl;
}
}
template <class T>
Tableau<T>::~Tableau(){
delete tab;
}
SVP j'ai besoin de votre aide! The best way to escape from a problem is to solve it. |