Description du problème: Je tente de créer une grande classe entière en utilisant la surcharge de l'opérateur, et je crois que jusqu'à présent tout va bien, mais je continue d'obtenir cette erreur lorsque je tente de compiler. Une idée de ce que le problème pourrait être? Cela ne me donne pas d'erreur pour l'entrée, seulement la sortie.bigint Surcharge de l'opérateur
Erreur: undefined reference to BIGINT :: toString() const »
#ifndef HEADER_H_INCLUDED
#define HEADER_H_INCLUDED
using namespace std;
class bigint{
public:
bigint(); //default constructor - set this to zero
bigint(int x0);
bigint(int x0, int x1);
bigint(int x0, int x1, int x2);
bigint(int x0, int x1, int x2, int x3);
bigint(int x0, int x1, int x2, int x3, int x4);
string tostring() const;
private:
int v[5];
};
ostream& operator <<(ostream & out, const bigint outpt){
out << outpt.tostring();
return out;
}
istream& operator >>(istream & in, const bigint& inpt){
return in;
} //need to fix this
bigint & operator +(const bigint & ls, const bigint & rs) {
return bigint(ls) + rs;
}//addition operator
bigint & operator -(const bigint & ls, const bigint & rs){
return bigint(ls) - rs;
} //subtraction operator
bool operator <(const bigint & ls, const bigint rs){
return bigint(ls) < rs;
} //use bool because these values can only be true or false
bool operator >(const bigint & ls, const bigint rs){
return bigint(ls) > rs;
}
bool operator >=(const bigint & ls, const bigint rs){
return bigint(ls) >= rs;
}
bool operator <=(const bigint & ls, const bigint rs){
return bigint(ls) <= rs;
}
bool operator ==(const bigint & ls, const bigint rs){
return bigint(ls) == rs;
}
bool operator !=(const bigint & ls, const bigint rs){
return bigint(ls) != rs;
}
#endif // HEADER_H_INCLUDED
Où est votre implémentation de tostring? –
Je ne vois pas d'implémentation de tostring(). – user1810087
Vous pourriez peut-être fournir un exemple de travail minimal dans lequel le problème apparaît, éliminer tout ce dont vous n'avez pas besoin (par exemple, constructeurs non utilisés, opérateurs non utilisés, etc ...). –