samedi 30 janvier 2016

CPP: Design and inheritance

I have this classes:

template<class T> class CNode
{
    friend class CTree<T>;

private:
    T data;
    ...
    CNode(data) : data(data) {}
    ...
public:
    ...
    T get_data() { return data;}
    void remove() { ... }
    ...
};


template<class T> class CSearchTree
{
private:
    CNode<T> * root;
    ...
public:
    ...
    void insert(T data) { /* Insert a new node... */ }
}

Everything is good so far. but when i try to extend this class to be a "Black Red Tree" i am lost.
I have 2 new classes: CBlackRedTree that inherit from CSearchTree and CBlackRedNode that inherit from CNode. The problem: When i call to insert function from CBlackRedTree, The function do everything fine but with CNode, But i wont CBlackRedTreeNode..
How do we solve it or how can I rewrite it differently so that it could work?
Thanks

Aucun commentaire:

Enregistrer un commentaire