所以我收到这个错误,这与我的AVLTree类继承我的BTree类的方式有关。据我所知,编译器的行为似乎无法找到BTree.h(位于同一目录中),或者只是不喜欢我包含它的方式。
我一直在网上寻找,但是我看到这个问题的大多数例子都涉及到有人忘记包含某些东西,所以我不确定下一步该做什么。
编辑:我还添加了BTree.h的代码示例
非常感谢任何帮助。
g ++ -g -w -Wall TreeTest.cpp BTree.h BinaryTree.h AVLTree.h -o testTrees在TreeTest.cpp中包含的文件中:12:0:AVLTree.h:22:29: 错误:'{'标记TreeTest.cpp之前的预期类名:在函数中
以下是代码:
#ifndef AVLTree_H
#define AVLTree_H
#include <vector>
#include <iostream>
#include "BTree.h"
using std::vector;
using std::cout;
using std::string;
template <class T>
class AVLTree : public BTree{
public:
struct TreeNode{
TreeNode * leftChild,
* rightChild;
T key;
vector<T> data;
int size;
int height;
bool deleted;
};
//Standard tree functions
AVLTree();
virtual ~AVLTree();
virtual bool isEmpty();
virtual int getSize();
virtual int getHeight();
virtual int insert(T key, T data); //returns number of insert calls
virtual int remove(T key); //returns number of remove calls
virtual int contains(T key); //removes number of contains calls, or 0 if doesn't exist
virtual std::vector<T> getData(T key);
//Special functions
virtual void displayAll();
virtual double getAverageDepth();
virtual int getTotalIPL(); //Retrieves internal path length from root
private:
int size;
TreeNode * root;
int * contains(T key, TreeNode * node, int calls);
int insert(T key, T data, TreeNode *& node, int calls);
int remove(T key, TreeNode *& node, int calls);
int getDepth(TreeNode*curr, int total);
int getIPL(TreeNode * start, int level);
void rotateLeft(TreeNode *& node);
void doubleLeft(TreeNode *& node);
void rotateRight(TreeNode *& node);
void doubleRight(TreeNode *& node);
int max(int a, int b);
int getHeight( TreeNode * t );
void display(TreeNode * node, string indent, bool last);
TreeNode * makeNode(T key, T data);
TreeNode * getNode(T key, TreeNode * node);
void destroySubTree(TreeNode * start);
};
这是BTree.h:
#ifndef bTree_H
#define bTree_H
#include <vector>
template <class T>
class BTree{
public:
struct TreeNode{
TreeNode * leftChild,
* rightChild;
T key;
std::vector<T> data;
int size;
};
//Standard tree functions
virtual ~BTree();
virtual bool isEmpty() = 0;
virtual int getSize() = 0;
virtual int getHeight() = 0;
virtual int insert(T key, T data) = 0; //returns number of insert calls
virtual int remove(T key) = 0; //returns number of remove calls
virtual int contains(T key) = 0;
virtual std::vector<T> getData(T key) = 0;
//Special functions
virtual void displayAll() = 0;
virtual double getAverageDepth() = 0;
virtual int getTotalIPL() = 0; //Retrieves internal path length from root
private:
int size;
TreeNode * root;
};
template <class T>
BTree<T>::~BTree<T>(){}
#endif
答案 0 :(得分:2)
由于BTree是一个类模板,你不能直接从它继承,但必须指定它的实例化。那就是你必须提供模板参数,在你的情况下,它应该与AVLTree实例化的类型相同。
template <class T>
class AVLTree:public BTree<T>