mardi 4 septembre 2018

inherit from inner class and pass it in on outer template simulateously?

I'm trying to create a tree structure where the user can make their own tree node inheritor, but the node encapsulates some code for managing its position in the tree and exposing children to inheritors. I have code similar to this:

template <typename TData>
class TreeBase {
protected:
    struct TreeNode { // should be fully encapsulated
        TData data;
        ...
    };
public: ...
};

template <typename TNode>
struct Tree: public TreeBase<TNode> {
    class Node {
        typename TreeBase<TNode>::TreeNode _tn; // keep encapsulated
    public: ...
    };
    ...
    static_assert(std::is_base_of<Node, TNode>::value, "TNode must be a descendant of NodeTrie::Node");
};

And though the class definitions compile, I can't figure out how to use them. I can't make an inheritor of Node without putting that inside an inheritor of Tree, and I can't make an inheritor of Tree without passing in my node type. It's a chicken & egg problem. Any suggestions?

Aucun commentaire:

Enregistrer un commentaire