Bonjour,
je crée une structure dans un fichier a.hpp:
[code]
struct sArgumentStr{
std::ostringstream valeur;
template <typename T>
sArgumentStr& operator << (T text);
std::string operator()();
void str (std::string& s );
void str (const char *c);
};
/code
dans un autre fichier (a.cpp), j'ai:
[code]
template <typename T>
sArgumentStr& sArgumentStr::operator << (T text){
valeur << text;
return *this;
}
std::string sArgumentStr::operator()(){
return valeur.str();
}
void sArgumentStr::str (std::string& s ){
valeur.str(s);
}
void sArgumentStr::str (const char *c){
std::string tmpstr = c;
valeur.str(tmpstr);
}
/code
et finalement, j'ai un troisième fichier, qui inclue a.hpp et utilise les surcharges des opérateurs de ma structure. Mais au linkage, j'obtiens l'erreur suivante (qui ne concerne que les surcharges d'opérateur, et non les méhodes de la classe):
command.cpp:(.text+0xb56): undefined reference to `sArgumentStr& sArgumentStr::operator<< <char const*>(char const*)'
command.cpp:(.text+0xb62): undefined reference to `sArgumentStr& sArgumentStr::operator<< <std::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
command.cpp:(.text+0xb72): undefined reference to `sArgumentStr& sArgumentStr::operator<< <char const*>(char const*)'
command.cpp:(.text+0xd07): undefined reference to `sArgumentStr& sArgumentStr::operator<< <char*>(char*)'
command.cpp:(.text+0xd1c): undefined reference to `sArgumentStr& sArgumentStr::operator<< <char const*>(char const*)'
[etc...]
Comment résoudre le problème?
Merci de votre aide!
Configuration: Linux
Firefox 3.0