Problème surchage d'opérateur
Bonjour,
j'ai besoin d'utiliser une librarire qui permet des calculs en précision arbitraire et également de pouvoir calculer des exponentielles et logarithme de ces nombres.
J'ai trouvé ça: http://www.hvks.com/Numerical/arbitrary_precision.htm. Et j'ai voulu l'inclure dans mon code. Mais j'ai des problèmes de compilation, le compilateur se demande quel opérateur il doit utiliser. Voici les erreurs de compilation:
Code:
1 2 3 4 5 6 7
| tables.cpp:431: erreur: ISO C++ indique qu'ils sont ambiguës même à travers la plus mauvaise conversion pour le premier que la plus mauvaise pour la seconde:
/usr/include/c++/4.1.3/istream:201: note: candidat 1: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(double&) [with _CharT = char, _Traits = std::char_traits<char>]
iprecision.h:1366: note: candidat 2: int_precision operator>>(const _Ty&, const int_precision&) [with _Ty = std::ifstream]
tables.cpp: In member function «void TwoDRowVectorTable::save(std::ostream&, Str2IdMap&)":
tables.cpp:450: erreur: ISO C++ indique qu'ils sont ambiguës même à travers la plus mauvaise conversion pour le premier que la plus mauvaise pour la seconde:
/usr/include/c++/4.1.3/bits/ostream.tcc:361: note: candidat 1: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char, _Traits = std::char_traits<char>]
iprecision.h:1331: note: candidat 2: int_precision operator<<(const _Ty&, const int_precision&) [with _Ty = std::ofstream] |
Les fonctions incriminées dans mon code:
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
| void TwoDRowVectorTable::load(istream& file, Str2IdMap& str2id)
{
string name1, name2;
double mean,sigma,weight;
RowVector newVector = RowVector(sizeDescSpace);
while (file>>name1>>name2>>weight) {
int i = 1;
ifstream vectFile(name2.c_str());
while (vectFile>>mean>>sigma) {
newVector(i) = mean;
i++;
}
add(str2id.getId(name1), str2id.getId(name2), newVector);
}
}
void TwoDRowVectorTable::save(ostream& file, Str2IdMap& str2id)
{
int k;
for (TwoDRowVectorTable::iterator i = begin(); i!=end(); i++) {
OneDRowVectorTable& vals = *i->second;
for (OneDRowVectorTable::iterator it = vals.begin(); it!=vals.end(); it++) {
string fileName = str2id.getStr(it->first)+".mean";
ofstream vectFile(fileName.c_str());
for(k = 1; k<= it->second.Ncols(); k++) {
vectFile << (double)exp(it->second(k)) << endl;
}
}
}
} |
et les fonctions de la bibliothèque:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| template <class _Ty> inline int_precision operator<<( int_precision& lhs, const _Ty& rhs )
{
return int_precision(lhs) <<= rhs;
}
template <class _Ty> inline int_precision operator<<( const _Ty& lhs, const int_precision& rhs )
{
return int_precision(lhs) <<= rhs;
}
template <class _Ty> inline int_precision operator>>( int_precision& lhs, const _Ty& rhs )
{
return int_precision(lhs) >>= rhs;
}
template <class _Ty> inline int_precision operator>>( const _Ty& lhs, const int_precision& rhs )
{
return int_precision(lhs) >>= rhs;
} |
Voila, si vous avez des explications quant au problème ou si vous connaissez d'autres lib qui permettent de faire ce que je veux (BigNum ne le permet pas)
Merci