I'm doing a dynamic numeric class, but when I go to test, I get the message "Program recived signal SIGSEGV" . I know this is a pointer error, but why does it occur and how do I fix it?
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef unsigned long ulong;
class Num
{
private:
vector<uchar> x;
ushort len;
...
public:
...
Num(vector<uchar> other)
{
if(other.size() > 8) other.resize(8);
while(other[other.size() - 1] == 0)
other.pop_back();
x = other;
len = x.size();
}
...
friend Num operator+(Num l, const Num& rhs)
{
Num r = rhs;
vector<uchar> res (l.x);
vector<uchar> mod (1, 0);
while(r.x.size() < res.size()) r.x.push_back(0);
while(r.x.size() > res.size()) res.push_back(0);
for(uchar i = 0; i < res.size(); i++)
{
mod.push_back((ushort)res[i] + (ushort)r.x[i] > 0xff);
res[i] += r.x[i];
}
if(mod.size() > 0) return (Num(res) + Num(mod));
return Num(res);
}
...
};