0

私は C++ を初めて使用し、BST クラスの関数の戻り値の型として Node* を使用できない理由について混乱しています (戻り値の型として使用する必要があります)。

私の推測では、Node クラスは「private」以外で宣言されていないためでしょうか?

BST クラスの残りの部分で Node* を使用する必要があるため、これを修正する方法はわかりません。

私に何ができるか教えてください:)

(また、別の答えを探しましたが、見つけたものはすべて異なるものと関係がありました

これが私のBSTクラスです:

#ifndef BST_H
#define BST_H

#include <string>

using namespace std;

//DO I HAVE TO CAPITALIZE ALL 'CONSTANTS' PER THE PROG. ASSIGNMENT EXPECTATIONS?
//DO CLASS OBJECTS HAVE TO BE CAPITALIZED?

class BST
{
    public:
        BST();
        ~BST();

        void deleteSubtree(Node* curr_root);

        void insertContent(const string& word, const string& definition);
        void deleteContent(string* word);
        const string* getContent(const string& word);
        Node* theRoot();
    //WHY DOES COMPLILING SAY NODE HAS NOT BEEN DECLARED?
        Node* treeMinimum(Node* ptr);
        void nodeTransplant(Node* oldN, Node* newN);

    private:
        class Node
        {
            public:
                Node(Node* cParent, string* word, string* definition)
                {parent=cParent; left=NULL; right=NULL; m_word=word; m_definition=definition;}

                Node* parent;  //IS IT OKAY THAT I ADDED IN A PARENT ATTRIBUTE TO NODES?
                Node* left;
                Node* right;
                string* m_word;
                string* m_definition;
        };

        Node* root;

};

また、別のクラスでほぼ同じことを行う方法を知りたいです (Node* を含む行は、Node が宣言されていないというエラーを返します)

#ifndef DICTIONARY_H
#define DICTIONARY_H

#include <string>
#include "BST.h"

using namespace std;

class Dictionary
{
    public:
        Dictionary();
        ~Dictionary();

        void add(const string& word, const string& definition);
        void remove(const string&);
        const string* getDefinition(const string& word);
        Node* getRoot();
        void printEntry(Node* ptr);
        void printInOrder(Node* ptr);
        void printPreOrder(Node* ptr);
        void printPostOrder(Node* ptr);

    private:
        BST dictionary;

};



#endif
4

0 に答える 0