引用文件出错...求大神指点

loseryao 2014-10-31 03:23:58
linearList.h

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;


}






seqList.h

#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);


}

seqList.cpp

#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);
}
}

}


test.cpp

#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...
...全文
145 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
幻夢之葉 2014-10-31
  • 打赏
  • 举报
回复
因为每一个cpp是一个编译单元啊,你要实例化一个模板,用到类类型参数的地方必须得对调用方可见! 你头文件引用不成功那你就先使用绝对路径试试,等其他错误解决了再考虑你路径写法,头文件包含目录等等!
loseryao 2014-10-31
  • 打赏
  • 举报
回复
引用 3 楼 jianwen0529 的回复:
你是模板啊! 你头文件声明,然后在在另一个文件里面实现! 对于test.cpp,你模板的实现对其不可见。 不可见当然就不能实例化成功! 而且你要实现所有的接口啊。
引用 3 楼 jianwen0529 的回复:
你是模板啊! 你头文件声明,然后在在另一个文件里面实现! 对于test.cpp,你模板的实现对其不可见。 不可见当然就不能实例化成功! 而且你要实现所有的接口啊。
为什么不可见啊...我设置的是public啊,而且好像我的引用没有成功,我写代码的时候没提示
幻夢之葉 2014-10-31
  • 打赏
  • 举报
回复
你是模板啊! 你头文件声明,然后在在另一个文件里面实现! 对于test.cpp,你模板的实现对其不可见。 不可见当然就不能实例化成功! 而且你要实现所有的接口啊。
loseryao 2014-10-31
  • 打赏
  • 举报
回复
引用 1 楼 xionggch 的回复:
#include "../seqList.h" 改成 #include "seqList.h"
引用 1 楼 xionggch 的回复:
#include "../seqList.h" 改成 #include "seqList.h"
改了...但还是报一样的错///
xionggch 2014-10-31
  • 打赏
  • 举报
回复
#include "../seqList.h" 改成 #include "seqList.h"

64,633

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧