0

Hey All

I am testing myself with making a big number class. Right now I'm just working with integers but I hope to expand it to floats as well. I am using a vector of integers for the container and i have run into a problem with my addition routine. I'm testing to see if one number is a negative or not and then calling the appropriate minus function but I am getting an error when trying to pass the this pointer to the function. The error I'm getting is:

error C2662: 'Number::operator -' : cannot convert 'this' pointer from 'const Number' to 'Number &'

here is my code that i have so far

```
Number.h
// inclusion guarding
#ifndef NUMBERCLASS_H
#define NUMBERCLASS_H
#include <string>
#include <vector>
class Number
{
public:
// constructors
Number();
Number(int);
Number(unsigned int);
Number(char *);
Number(std::string);
// destructor
~Number() {};
// get functions
int GetNumberAsInt(); // return as a int if possible otherwise returns 0 and flags error
std::string GetNumber();
bool GetSign(); // reuturns true if negative
bool GetToBig(); // returns true if GetNumberAsInt fails
// math operators
Number & operator=(const Number &);
Number & operator+(const Number &);
Number & operator-(const Number &);
private:
// private functions
char* makeInt(char *);
// private data
std::vector<int> data;
int length;
bool sign;
bool toBig;
};
#endif
```

```
Number.cpp operator+ function
Number & Number::operator +(const Number & number)
{
int carry = 0;
int size = 0;
if (sign && !number.sign)
{
return number.operator -(*this); // this is where I'm getting my error
}
if (number.sign && !sign)
{
return this->operator -(number);
}
std::vector<int>::const_iterator firstIt;
std::vector<int>::const_iterator secondIt;
std::vector<int> temp;
if (number.length > length)
{
firstIt = data.begin();
secondIt = number.data.begin();
}
else
{
firstIt = number.data.begin();
secondIt = data.begin();
}
while (*firstIt)
{
carry = carry + *firstIt + *secondIt;
if (carry >= 10)
{
temp.push_back(carry - 10);
if (carry == 10)
carry = 1;
else
carry -= 10;
}
else
{
temp.push_back(carry);
carry = 0;
}
firstIt++;
secondIt++;
}
while (*secondIt)
{
if (carry > 0)
{
carry = carry + *secondIt;
if (carry >= 10)
{
temp.push_back(carry - 10);
if (carry == 10)
carry = 1;
else
carry -= 10;
}
else
{
temp.push_back(carry);
carry = 0;
}
}
else
{
temp.push_back(*secondIt);
}
secondIt++;
}
data = temp;
return *this;
}
```

Any help would be appreciated. Any other advice would also be appreciated.