Warum fehlen mir die Rechte?



  • Warum fehlen mir hier die Rechte, Allocation is doch verwand mit Node und Node *m_next is protected?
    Geht bitte nicht auf den Code ein ist eine Übung dich noch net fertig ist.

    #include <iostream>
    using namespace std;
    
    class Node
    {
        public:
        Node(const int &save_=0,Node *next_=0);
    
        protected:
        int m_save;
        Node *m_next;
    };
    
    Node::Node(const int &save_,Node *next_)
    :m_save(save_),m_next(next_)
    {
    
    }
    
    class Allocation : public Node
    {
        public:
        Allocation();
        void push_back(const int &value);
    
        private:
        Node m_head;
        Node *m_end;
    };
    
    Allocation::Allocation()
    :m_end(&m_head)
    {
    
    }
    
    void Allocation::push_back(const int &value)
    {
        m_end->m_next=new Node(value);
    }
    
    int main()
    {
    
        return 0;
    }
    

    Compiling: C:\MinGW\Andi\ferien_projekt.cpp
    C:\MinGW\Andi\ferien_projekt.cpp: In member function void Allocation::push\_back(const int&)': C:\\MinGW\\Andi\\ferien\_projekt.cpp:11: error:Node*Node::m_next' is protected
    C:\MinGW\Andi\ferien_projekt.cpp:39: error: within this context
    Process terminated with status 1 (0 minutes, 0 seconds)
    2 errors, 0 warnings

    MfG
    Stromberg



  • Allocation is doch verwand mit Node

    Warum ist Allocation ein Node? Das macht doch garkeinen Sinn.



  • Stromberg schrieb:

    Geht bitte nicht auf den Code ein ist eine Übung dich noch net fertig ist.

    Ich wollte doch nur wissen warum ich kein Zugriff auf m_data habe!?

    MfG
    Stromberg



  • m_head und m_end und m_next sind unabhängige Objekte(bzw. Zeiger auf Objekte) der Klasse Node, d.h. es gilt auch für Allocation die von Node vorgegebene Schnittstelle.



  • Ach so, das würde jetzt nur bei sowas gehen:
    Node a=new Allocation;
    ???



  • Hm, weiß jetzt leider nicht wie du das meinst. Wenn wir darüber reden, dass man in der Klasse Allocation z.B. m_end nicht als Zeiger auf Node sonder als Zeiger auf Allocation deklariert, dann ja, dann hättest du direkten Zugriff auf m_end->m_next.

    Aber, auf m_end->m_next->m_next wieder nicht mehr, da m_next ja ein Zeiger auf Node ist.


Anmelden zum Antworten