How to use a Node pointer as a return type in a BST class?

334 views Asked by At

I am new to C++ and I am confused as to why I cannot utilize Node* as a return type for functions in my BST class (I have to use it as a return type).

My guess is because Node class is not declared except for in 'private'?

Though I am not sure how to fix this because I HAVE to use Node* in the rest of my BST class.

Please let me know what I could do :)

(Also I searched for another answer, but everything I found had to do with different

Here is my BST class:

#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;

};

Also, I would like to know how to do the same thing almost, in another class (lines with the Node* in them return errors saying Node has not been declared)

#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
0

There are 0 answers