0

I hope you can give me a hand, I have searched the forum but I haven't found anything similar.

I have written these two classes:

//AbstrTree.h
#ifndef TREE_ABSTRTREE_H
#define TREE_ABSTRTREE_H

#include <iostream>

using namespace std;

template <class T>
class AbstrTree
{
protected:
    struct node
    {
        T label;
        node *left, *right;
        node(T info)
        {
            label = info;
            left = right = NULL;
        }
    };
    node *root;

    virtual void deleteNode(T, node *&) = 0;
    virtual node* findNode(T, node*);
    void preOrder(node *);
    void inOrder(node *);
    void postOrder(node *);
    virtual void delTree(node *&);
    virtual void printTree(node *) = 0;
    bool createNode(T, node *&);

public:
    AbstrTree() { root = NULL; };
    virtual ~AbstrTree() { delTree(root); };
    virtual int insert(T,T) = 0;
    bool find(T);
    void removeNode(T);
    virtual void pre();
    virtual void post();
    virtual void in();
    void print();
};
#endif

//BinTree.h
#ifndef TREE_BINTREE_H
#define TREE_BINTREE_H

#include "AbstrTree.h"

template <class T>
class BinTree : public AbstrTree<T>
{
    protected:
        virtual void deleteNode(T,  node*&);
        virtual void printTree(node*);
    public:
        BinTree();
        ~BinTree();

        virtual bool insert(T, T);
        bool insert(T, T,char);
};

#endif

The problem is this, in the BinTree subclass, the 'node' struct I declared in AbstrTree is undefined.

Clion says exactly this:

Unknown type name 'node'

Can anyone understand why?

Sirius
  • 1
  • 1
    You need to say `typename AbstrTree::node` rather than just `node`. To save typing, you can add an alias `using node = typename AbstrTree::node;` and then use just `node`. – n. m. could be an AI Dec 17 '20 at 09:23
  • [Related issue](https://stackoverflow.com/questions/4643074/why-do-i-have-to-access-template-base-class-members-through-the-this-pointer). – n. m. could be an AI Dec 17 '20 at 09:25

0 Answers0