Un bout de code est parfois plus simple pour expliquer le pb :
Matrice.h
Code :
- #ifndef MATRICE_H
- #define MATRICE_H
- #include <vector>
- template <class T>
- class Matrice
- {
- protected:
- unsigned int nL,nC;
- std::vector<T> donnees;
- public:
- Matrice();
- virtual ~Matrice();
- };
- #endif //MATRICE_H
|
Matrice.cpp
Code :
- #include "stdafx.h"
- #include "Matrice.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- template<class T>
- Matrice<T>::Matrice()
- {
- nL = nC = 0;
- }
- template<class T>
- Matrice<T>::~Matrice()
- {
- donnees.clear();
- nC = nL = 0;
- }
|
et test.cpp
Code :
- #include "stdafx.h"
- #include "Matrice.h"
- int main(int argc, char* argv[])
- {
- Matrice<float> M;
- printf("Hello World!\n" );
- return 0;
- }
|
Resultat de compilation :
Compiling...
Matrice.cpp
test.cpp
Generating Code...
Linking...
test.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall Matrice<float>::~Matrice<float>(void)" (??1?$Matrice@M@@UAE@XZ)
test.obj : error LNK2001: unresolved external symbol "public: __thiscall Matrice<float>::Matrice<float>(void)" (??0?$Matrice@M@@QAE@XZ)
Debug/test.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
test.exe - 3 error(s), 0 warning(s)
Je croyais avoir capte les template, et du coup je ne vois pas d'ou ca vient. J'ai lu sur le forum qu'il y avait des pb avec la stl, les template et Visual Studio 6.0, ce probleme en fait-il partie ?
Merci
Message édité par marmotte.tranquille le 20-03-2003 à 21:37:42