Wywołanie metody klasy przy przeciążaniu operatora

0

Hej! Piszę na zajęcia bibliotekę mającą umożliwiać operacje na dowolnie dużych liczbach (dodawanie i odejmowanie). Pomysł z jakiego chcę skorzystać to aby w operatorze liczby były odwracane(np 1023 do 3201), a następnie tworzona pomocnicza struktura "liczba" będąca po prostu przeniesieniami z dodawania pod kreską. Funkcję która odwraca kolejkę liczb już mam, problem pojawia się gdy chcę ją wywołać w operatorze dodawania. Nie chce się to za nic skompilować. W jaki sposób mogę użyć funkcji rev() w operatorze dodawania?

#ifndef QUEUE_H
#define QUEUE_H

#include <iostream>
#include <stdexcept>

using namespace std;

class Queue
{
    class Node
    {
    public:
        char cont;
        Node* next;
        Node* pred;
        Node(char c, Node* n = nullptr, Node* p = nullptr)
        {
            cont = c;
            next = n;
            pred = p;
        }
    };
    Node* head = nullptr;
    Node* tail = nullptr;
    int howBig = 0;
public:
    Queue() = default;
    ~Queue()
    {
        if(howBig == 0)
            cout << "Structure is empty." << endl;
        else
        {
            Node* killer;
            while(head != nullptr)
            {
                killer = head;
                head = head->next;
                delete killer;
                howBig--;
            }
            cout << "Structure deleted. " << endl;

        }
    }
    void show()
    {
        if(howBig == 0)
            throw logic_error("The structure is empty!");
        else
        {
            Node* runner = head;
            while(runner != nullptr)
            {
                cout << runner->cont;
                runner = runner-> next;
            }
        }

    }
    void add(char a)
    {
        Node* _new = new Node(a);
        if(head == nullptr)
        {
            head = _new;
            tail = _new;
        }
        else
        {
            tail->next = _new;
            tail = tail->next;
        }
        howBig++;
    }
    void addToBeginning(char a)
    {
        Node* _new = new Node(a);
        if(head == nullptr)
        {
            head = _new;
            tail = _new;
        }
        else
        {
            _new->next = head;
            head = _new;
        }
        howBig++;

    }
    void rev()
    {
        if(howBig == 0)
            throw logic_error("Structure is empty!");
        else
        {

            int i = 0;
            Node* firsthead = head;
            Node* pom = firsthead->next;
            while(firsthead->next!=nullptr)
            {
                firsthead->next = firsthead->next->next;
                pom->next = head;
                head = pom;
                pom = firsthead->next;
            }

        }


    }

    Queue operator+ (const Queue &q) const
    {
        q.rev();
        this.rev();


    }
    //Queue operator- (const Queue &q) const;



};

#endif // QUEUE_H

2

Zrób inną reprezentację:

class BigUnsignedValue
{
    private:
    string value; // inverted value
    private BigUnsignedValue(ostringstream ss):value(ss.str()) {}
    friend BigUnsignedValue add(const BigUnsignedValue &va,const BigUnsignedValue &vb)
    {
        ostringstream ss;
        int curry=0,next=0,a=0,b=0;
        for(;(a<va.size())&&(b<ba.size());curry=next)
        {
            curry+=va[a++]-'0'+vb[b++]-'0';
            next=curry%10;
            ss<<(char)(curry-10*next+'0');
        }
        return BigUnsignedValue(ss);
    }
    BigUnsignedValue operator+(const BigUnsignedValue &vb)const { return add(*this,vb);  }
    BigUnsignedValue operator-(const BigUnsignedValue &vb)const;
};
class BigSignedValue
{
    private:
    BigUnsignedValue value;
    bool sign; // true if negative value
    BigSignedValue operator+(const BigSignedValue &vb)const;
    BigSignedValue operator-(const BigSignedValue &vb)const;
};

Pisane na kolanie, mogą być drobne błedy.

1 użytkowników online, w tym zalogowanych: 0, gości: 1