【问题】使用GCC编译c++程序遇到的protected继承问题

// 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没有在使用范围内声明。

现在不知道是什么原因。


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值