1

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

错误:未定义对 `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
4

1 回答 1

4

我没有看到您的tostring()编码实现。您必须编写自己的tostring().

该函数将获取数字,将其转换为字符串并返回该字符串。您可以使用stream或。itoasprintf

如果其他地方有任何本地tostring()方法,请检查“字符串”的 S 是否肯定是大写而不是小写 ( toString())。

于 2013-06-05T14:35:39.077 回答