// 2014/8/21
首先使用的程序来自数据结构一本书。
程序中有两个头文件,第一个头文件linearlist.h:
5 #include<iostream>
6 using namespace std;
7 template <class T>
8 class LinearList
9 {
10 public:
11 virtual bool IsEmpty() const=0;
12 virtual int Length() const=0;
13 virtual bool Find(int i,T& x) const=0;
14 virtual int Search(T x) const=0;
15 virtual bool Insert(int i,T x)=0;
16 virtual bool Delete(int i)=0;
17 virtual bool Update(int i,T x)=0;
18 virtual void Output(ostream& out)const=0;
19 protected:
20 int n;//length of the linearlist
21 };
第二个头文件seqlist.h,中包含另一个类模板:
9 template <class T>
10 class SeqList:public LinearList<T>
11 {
12 public:
13 SeqList(int mSize);
14 ~SeqList(){delete []elements;}
15 bool IsEmpty()const;
16 int Length()const;
17 bool Find(int i,T& x)const;
18 int Search(T x)const;
19 bool Insert(int i,T x);
20 bool Delete(int i);
21 bool Update(int i,T x);
22 void Output(ostream& out)const;
23 private:
24 int maxLength;
25 T * elements;
26 };
seqlist.h头文件中还有其中函数的实现,问题跟函数实现无关,所以没有给出。
用这两个头文件实现两个集和的操作,具体实现就不给出了,问题也不是出在这上面。
用GCC编译的时候出了问题:
[chen@localhost linelist]$ g++ test_Union.cpp seqlist.h -o test_Union
In file included from test_Union.cpp:6:0:
seqlist.h: In constructor ‘SeqList<T>::SeqList(int)’:
seqlist.h:31:2: error: ‘n’ was not declared in this scope
n = 0;
^
seqlist.h: In member function ‘bool SeqList<T>::IsEmpty() const’:
seqlist.h:36:9: error: ‘n’ was not declared in this scope
return n==0;
^
.
.
.
很多错误,原因都是一样的,是说SeqList中的函数中用到的n没有在使用范围内声明。
现在不知道是什么原因。