I am training my C ++ and I am trying to write a library that will represent the following number using linked lists:
999999999 * ([i = 0] Σ [999999999] 1,000,000,000 ^ i)
For example, if my number is 711381450277869054011 , it will be represented as follows:
711 * 1 000 000 000 ^ 2 + 381450277 * 1 000 000 000 ^ 1 + 869054011 > * 1 000 000 000 ^ 0
So, here is the structure of my LL and it functions:
typedef struct node* ll; struct node { unsigned int data; ll next; }; bool insert(ll&, unsigned int);
And here is my class of unsigned very long integers:
class uli { public: uli(); ~uli(); // <<, >>, =, operators... uli& operator +=(const uli&); uli& operator +=(char*); const uli operator +(const uli&); private: ll head; }; uli::uli() { head = NULL; insert(head, 0); } uli::~uli() { destroy(head); }
Operator
+ = works fine, and I use it to overload the + operator.
The problem is that I cannot get the operator + () method to return const uli without destroying it with the deconstructor before I use it.
const uli uli::operator +(const uli& rarg)
Now I can not do Z = X + Y;