64,633
社区成员
发帖
与我相关
我的任务
分享
template <class T>
class LinearList
{
LinearList();
~LinearList();
virtual int Size() const= 0;
virtual int length() const = 0;
virtual int Search(T& x) const = 0;
virtual int Locate(int i) const = 0;
virtual bool getData(int i,T& x)const = 0;
virtual void setData(int i,T& x) const = 0;
virtual bool Insert(int i,T& x)const = 0;
virtual bool Remove(int i,T& x) const = 0;
virtual bool IsEmpuy() const = 0;
virtual bool IsFull() const = 0;
virtual void Sort() const = 0;
virtual void input() const = 0;
virtual void output() const = 0;
virtual LinearList<T> operator=(LinearList<T> &L)=0;
}
#include<iostream>
#include<stdlib.h>
#include "../linearList.h"
const int defaultSize = 100;
template <class T>
class SeqList:public LinearList<T>
{
protected:
T *data;
int maxSize;
int last;
void reSize(int size);
public:
SeqList(int sz = defaultSize);
SeqList(SeqList<T> &L);
~SeqList(){delete[] data;}
int Size()const{return maxSize;}
int Leagth() const{return last+1;}
bool getData(int i,T &x )const
{
if(i>0 && i<=last+1)
{
x = data[i-1];
return true;
}
else
{
return false;
}
}
void setData(int i,T &x)
{
if(i>0 && i<=last+1)
{
data[i-1] = x;
}
}
bool Insert(int i,T& x);
bool Remove(int i,T& x);
bool IsEmpty(){return (last == -1)?true;false;}
bool IsFull(){return (last == maxSize - 1)?true;false;}
void input();
void output();
SeqList<T> operator= (SeqList<T> &L);
}
#include "../seqList.h"
template <class T>
SeqList<T>::SeqList(int sz){
if(sz > 0)
{
maxSize = sz;
last = -1;
data = new T[maxSize];
if(data = NULL)
{
cerr<<"存储分配错误!"<<endl;exit(1);
}
}
}
#include<iostream>
#include "../seqList.h"
int main()
{
SeqList<int> seq(8);
}
1>SeqList.cpp
1>f:\c++coding\study\study\seqlist.h(4) : error C2143: syntax error : missing ';' before 'const'
1>f:\c++coding\study\study\seqlist.cpp(2) : error C2143: syntax error : missing ';' before 'template'
1>test.cpp
1>f:\c++coding\study\study\seqlist.h(4) : error C2143: syntax error : missing ';' before 'const'
1>f:\c++coding\study\study\test.cpp(5) : error C2143: syntax error : missing ';' before 'int'
1>f:\c++coding\study\study\test.cpp(7) : error C2259: 'SeqList<T>' : cannot instantiate abstract class
1> with
1> [
1> T=int
1> ]
1> due to following members:
1> 'int LinearList<T>::length(void) const' : is abstract
1> with
1> [
1> T=int
1> ]
1> f:\c++coding\study\study\linearlist.h(7) : see declaration of 'LinearList<T>::length'
1> with
1> [
1> T=int
1> ]
1> 'int LinearList<T>::Search(T &) const' : is abstract
1> with
1> [
1> T=int
1> ]
1> f:\c++coding\study\study\linearlist.h(8) : see declaration of 'LinearList<T>::Search'
1> with
1> [
1> T=int
1> ]
1> 'int LinearList<T>::Locate(int) const' : is abstract
1> with
1> [
1> T=int
1> ]
1> f:\c++coding\study\study\linearlist.h(9) : see declaration of 'LinearList<T>::Locate'
1> with
1> [
1> T=int
1> ]
1> 'void LinearList<T>::setData(int,T &) const' : is abstract
1> with
1> [
1> T=int
1> ]
1> f:\c++coding\study\study\linearlist.h(11) : see declaration of 'LinearList<T>::setData'
1> with
1> [
1> T=int
1> ]
1> 'bool LinearList<T>::Insert(int,T &) const' : is abstract
1> with
1> [
1> T=int
1> ]
1> f:\c++coding\study\study\linearlist.h(12) : see declaration of 'LinearList<T>::Insert'
1> with
1> [
1> T=int
1> ]
1> 'bool LinearList<T>::Remove(int,T &) const' : is abstract
1> with
1> [
1> T=int
1> ]
1> f:\c++coding\study\study\linearlist.h(13) : see declaration of 'LinearList<T>::Remove'
1> with
1> [
1> T=int
1> ]
1> 'bool LinearList<T>::IsEmpuy(void) const' : is abstract
1> with
1> [
1> T=int
1> ]
1> f:\c++coding\study\study\linearlist.h(14) : see declaration of 'LinearList<T>::IsEmpuy'
1> with
1> [
1> T=int
1> ]
1> 'bool LinearList<T>::IsFull(void) const' : is abstract
1> with
1> [
1> T=int
1> ]
1> f:\c++coding\study\study\linearlist.h(15) : see declaration of 'LinearList<T>::IsFull'
1> with
1> [
1> T=int
1> ]
1> 'void LinearList<T>::Sort(void) const' : is abstract
1> with
1> [
1> T=int
1> ]
1> f:\c++coding\study\study\linearlist.h(16) : see declaration of 'LinearList<T>::Sort'
1> with
1> [
1> T=int
1> ]
1> 'void LinearList<T>::input(void) const' : is abstract
1> with
1> [
1> T=int
1> ]
1> f:\c++coding\study\study\linearlist.h(17) : see declaration of 'LinearList<T>::input'
1> with
1> [
1> T=int
1> ]
1> 'void LinearList<T>::output(void) const' : is abstract
1> with
1> [
1> T=int
1> ]
1> f:\c++coding\study\study\linearlist.h(18) : see declaration of 'LinearList<T>::output'
1> with
1> [
1> T=int
1> ]
1>Generating Code...