Impossible d'appeler le constructeur template
Bonjour, j'avais déjà créé un post sur la virtualisation de méthodes template ici.
Et maintenant que j'ai les infos qu'il me faut j'ai donc poursuivi la chose (donc ceci est la suite en quelque sorte de mon ancien post)
J'ai donc créer une classe Variable:
Variable.h
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 38 39 40
|
#ifndef DEF_VARIABLE
#define DEF_VARIABLE
#include "../All.cpp"
class Variable
{
// Constructeur
public:
Variable();
Variable(int);
Variable(Variable const& v);
template<typename T>
Variable(T n);
// Attributs
public:
private:
typeVar type;
boost::any val;
protected:
// Méthodes
public:
virtual void incremente();
virtual void decremente();
virtual std::string toString();
virtual std::string typeNameToString();
virtual unsigned int getMemorySize();
};
#endif |
Variable.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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#include "../All.cpp"
#include "Variable.h"
using namespace std;
Variable::Variable(){
}// TEMP : TODO
Variable::Variable(int i){
}// TEMP : TODO
Variable::Variable(Variable const& v) {
}// TEMP : TODO
template<typename T>
Variable::Variable(T n){
val=n;
if(typeid(n)==typeid(int)){
cout << "int!" << endl;
type=i_int;
} else if(typeid(n)==typeid(unsigned int) || typeid(n)==typeid(uint)){
cout << "uint!" << endl;
type=i_uint;
} else if(typeid(n)==typeid(char)){
cout << "char!" << endl;
type=i_char;
} else if(typeid(n)==typeid(unsigned char) || typeid(n)==typeid(uchar)){
cout << "unsigned char!" << endl;
type=i_uchar;
} else {
cout << "? ? ?" << endl;
type=i_notype;
}
}
void Variable::incremente(){}// TEMP : TODO
void Variable::decremente(){}// TEMP : TODO
string Variable::toString(){
return "NoValue"; // TEMP : TODO
}
string Variable::typeNameToString(){
return "NoValue"; // TEMP : TODO
}
unsigned int Variable::getMemorySize(){
return sizeof(*this); // TEMP : TODO
} |
Et voici main.cpp qui test cette classe:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#include "All.cpp"
using namespace std;
int main()
{
new Variable();
new Variable((int)5);
new Variable((char)5); // plante
#ifdef DEBUG_TIMERS
cout << endl <<"Temps d'execution (ms): "<< clock() << endl;
#endif
return returnCode;
} |
Et voila le message du compilo (gcc) :
Citation:
undefined reference to `Variable::Variable<char>(char)'
:cry:
Pourtant le constructeur existe et il est accessible puisque les 2 lignes au dessus de celle qui plante fonctionnent.
D'où vient le problème svp?:oops: