Question

Description of problem: I'm attempting to create a big integer class using operator overloading, and I believe so far so good, but I keep getting this error when I attempt to compile. Any idea what the problem could be? It doesn't give me an error for the input, only the output.

Error: 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
Was it helpful?

Solution

I don't see your implementation of tostring() coded. You must code your own implementation of tostring().

The function will get the number, convert it to a string and return the string. You can use stream, itoa or sprintf.

If there is any native tostring() method elsewhere, check that the S of "string" surely will be uppercase instead of lowercase (toString()).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top