在尝试实例化模板化类的数据成员时,我不断收到此错误:
Proj3Aux.h:28: error: ISO C++ forbids declaration of ‘AugmentedBinarySearchTree’ with no type
Proj3Aux.h:28: error: expected ‘;’ before ‘<’ token
以下是我尝试实例化的类I中的代码:
class Proj3Aux
{
private:
AugmentedBinarySearchTree<int> m_tree; <-- ERROR HERE
string m_currentCmd;
vector<int> m_inputs;
由于某种原因,实例化类型为int
的ABST的调用会引发某种错误。
以下是ABST类的标题代码:
template <class Comparable>
class AugmentedBinarySearchTree
{
public:
/*------------Constructors/Destructors-------------*/
explicit AugmentedBinarySearchTree();
AugmentedBinarySearchTree(const AugmentedBinarySearchTree<Comparable> & rhs);
~AugmentedBinarySearchTree();
/*--------------Facilitators------------------------*/
int remove(const Comparable & x);
bool IsPerfect();
// bool IsComplete(); <-- Extra Credit!
void PrintLevels(int numlevels);
void makeEmpty();
/*---------------Getters---------------------------*/
int RemoveResidue(); /* Assume RemoveResidue will always be called after Prin\
t */
const Comparable & NthElement(int n);
int Rank(const Comparable & x);
const Comparable & Median();
BinaryNode<Comparable> * findMin(BinaryNode<Comparable> *t) const;
/*---------------Setters---------------------------*/
int insert(const Comparable & x);
private:
int insert(const Comparable & x, BinaryNode<Comparable> * & t) const;
int remove(const Comparable & x, BinaryNode<Comparable> * & t) const;
void PrintLevels(queue <BinaryNode<Comparable> *> q, int levels);
void RemoveResidue(BinaryNode<Comparable> * & t, int *deletions) const;
BinaryNode<Comparable> * NthElement(BinaryNode<Comparable> *t, int *nodesVisi\
ted, int n) const;
void Rank(const Comparable & x, BinaryNode<Comparable> *t, int *nodesVisited)\
const;
bool IsPerfect(queue <BinaryNode<Comparable> *> q, int height);
void makeEmpty(BinaryNode<Comparable> * & t) const;
//IsComplete <-- Extra Credit!
/*------------------Members-----------------------------*/
BinarySearchTree<Comparable> m_tree;
BinaryNode<Comparable> *root;
};
#include "AugmentedBinarySearchTree.cpp"
BinaryNode
类的定义高于给定的代码,在ABST cpp文件中,所有方法都以正确的方式定义:
template <class Comparable>
<return type> AugmentedBinarySearchTree<Comparable>::<method>(<parameters>)
请帮忙吗?
编辑:
Proj3Aux.h
的开头:
#ifndef PROJ3_AUX_H_
#define PROJ3_AUX_H_
#include <iostream>
#include <string>
#include <fstream>
#include "AugmentedBinarySearchTree.h"
using namespace std;
const char COMMENT = '#';
class Proj3Aux
{
private:
//AugmentedBinarySearchTree<int> m_tree;
string m_currentCmd;
vector<int> m_inputs;
public:
/*
* Enum to contain all commands available
*/
enum COMMANDS {PRINT, RESIDUALS, RANK, NTH, MEDIAN, REMOVE, PERFECT,
COMPLETE};
/*
* Proj3Aux
* Default class constructor
* Preconditoins: none
* Postconditions: new instance of Proj3Aux is created
*/
Proj3Aux();