[Templates] Erreur à l'édition des liens
Bonjour à tous,
Je suis en train d'essayer de concocter une petite classe Point en utilisant les template. J'ai pour le moment ceci :
Point.h
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#if ! defined ( POINT_H )
#define POINT_H
template < typename T > class Point
{
public:
T x;
T y;
Point ( );
Point ( T aX, T aY);
virtual ~Point ( );
};
#include "Point.cpp"
#endif // POINT_H |
Point.cpp
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
|
#include "Point.h"
template <typename T>
Point<T>::Point ( )
{
#ifdef MAP
cout << "Appel au constructeur de <Point>" << endl;
#endif
}
template <typename T>
Point<T>::Point ( T aX, T aY):x(aX),y(aY)
{
#ifdef MAP
cout << "Appel au constructeur de <Point(aX,aY)>" << endl;
#endif
}
template <typename T>
Point<T>::~Point ( )
{
#ifdef MAP
cout << "Appel au destructeur de <Point>" << endl;
#endif
} |
CMobile.h
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#if ! defined ( CMOBILE_H )
#define CMOBILE_H
#include "Point.h"
class CMobile
{
public:
CMobile ( const CMobile & unCMobile );
CMobile ( );
virtual ~CMobile( );
protected:
Point<int> position;
};
#endif |
CMobile.cpp
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include "CMobile.h"
47 : CMobile::CMobile ( const CMobile & aCMobile )
{
#ifdef MAP
cout << "Appel au constructeur de copie de <CMobile>" << endl;
#endif
54 : }
57: CMobile::CMobile ( )
{
#ifdef MAP
cout << "Appel au constructeur de <CMobile>" << endl;
#endif
64: }
CMobile::~CMobile ( )
{
#ifdef MAP
cout << "Appel au destructeur de <CMobile>" << endl;
#endif
74: } |
(Les numéros en rouge en gras correspondent aux numéros de lignes)
Lors de la compilation j'ai le message d'erreur suivant :
Citation:
Génération du fichier <./obj/Point.o>
../sources/Point.cpp:54: erreur: expected constructor, destructor, or type conversion before ‘<’ token
../sources/Point.cpp:64: erreur: expected constructor, destructor, or type conversion before ‘<’ token
../sources/Point.cpp:74: erreur: expected constructor, destructor, or type conversion before ‘<’ token
make: *** [Point.o] Erreur 1
Quelqu'un aurait une idée de l'origine de l'erreur ?
Par avance merci :)
Merci par avance