У меня возникли проблемы с разбивкой кода на повторно используемые части с использованием шаблонов и наследования.Я хотел бы добиться, чтобы мой класс дерева и класс avltree использовали один и тот же класс узла, а класс avltree наследовал некоторые методы из класса дерева и добавил некоторые конкретные.Итак, я пришел с кодом ниже.Компилятор выдает ошибку в tree.h, как отмечено ниже, и я не знаю, как это преодолеть.Любая помощь приветствуется!:)
node.h:
#ifndef NODE_H
#define NODE_H
#include "tree.h"
template <class T>
class node
{
T data;
...
node()
...
friend class tree<T>;
};
#endif
tree.h
#ifndef DREVO_H
#define DREVO_H
#include "node.h"
template <class T>
class tree
{
public: //signatures
tree();
...
void insert(const T&);
private:
node<T> *root; //missing type specifier - int assumed. Note: C++ does not support default-int
};
//implementations
#endif
avl.h
#ifndef AVL_H
#define AVL_H
#include "tree.h"
#include "node.h"
template <class T>
class avl: public tree<T>
{
public: //specific
int findMin() const;
...
protected:
void rotateLeft(node<T> *)const;
private:
node<T> *root;
};
#endif
avl.cpp (Iпопытался отделить заголовки от реализации, это работало до того, как я начал комбинировать код avl с кодом дерева)
#include "drevo"
#include "avl.h"
#include "vozlisce.h"
template class avl<int>; //I know that only avl with int can be used like this, but currently this is doesn't matter :)
//implementations
...