问题描述:我正在尝试使用运算符重载创建一个大整数类,我相信到目前为止一切都很好,但是当我尝试编译时,我不断收到这个错误。知道问题可能是什么吗?它不会给我输入错误,只有输出。
错误:未定义对 `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