I am attempting to create a Big Integer class but have run into an issue. I have an overloaded constructor that's giving me some issues. It is supposed to take in a string and convert that string into a std::uint8_t*
called m_number
, keep track of the number of digits, and keep track of space allocated for each std::uint8_t*
. The numbers are loaded in backwards, with the least significant digit being m_number[0]
. The issue I'm having is with storing '0' into the array. The function works fine for any other value, but if a string has a '0' in it, the function stops storing values into the std::uint_8*
.
Here is my class definition:
class BigInteger
{
public:
BigInteger add(const BigInteger& rhs);
BigInteger multiply(const BigInteger& rhs);
void display();
BigInteger();
BigInteger(const BigInteger& rOther);
BigInteger(int);
BigInteger(std::string);
BigInteger& operator=(const BigInteger & rhs);
private:
std::uint8_t* m_number;
unsigned int m_sizeReserved;
unsigned int m_digitCount;
}
Here's my overloaded constructor:
BigInteger::BigInteger(std::string str) {
m_digitCount = str.length();
m_sizeReserved = m_digitCount;
m_number = new std::uint8_t[m_sizeReserved];
std::uint8_t* aArray = new std::uint8_t[m_sizeReserved];
int j = str.length()-1;
for(int i=0; i < m_digitCount; i++, j--) {
aArray[i] = str[j]-'0';
}
for(int i=0; i < m_digitCount; i++) {
m_number[i] = aArray[i];
}
delete[] aArray;
}