C++error4430

饭fan有引力 2010-11-03 11:29:25
第一次准备自己写顺序表,不用教程上面的,没想到出现这种问题

#ifndef TEST_H
#define TEST_H

#include <iostream>
using namespace std;

//----------------------顺序表的类声明----------------------------//
template <class T> class SeqList
{
private:
T *data; //存放数组
int maxSize; //顺序表的大小
int last; //当前已存储的顺序表的最后一个位置(从0开始0)
public:
SeqList(); //默认构造函数
SeqList(int maxS); //构造长度为maxSize的顺序表
//SeqList<T> operator = (SeqList<T> &L); //表整体赋值
~SeqList(); //析构函数
void input(); //输入函数
void output(); //输出函数
bool insert(int i, T &x); //插入x到第i个表项之后
bool remove(int i, T &x); //删除第i个表项,通过x返回表项的值
bool IsEmpty(); //判断顺序表是否为空
bool IsFull(); //判断顺序表是否已满
bool getData(int i, T &x); //取出第i个表项的值
int Locate(int i); //定位第i个元素,函数返回表项序号
};

template<class T> SeqList<T>::SeqList(int maxS)
{
maxSize = maxS;
}

template<class T> SeqList<T>::~SeqList()
{
}

template<class T> SeqList<T>::input()
{
for(int i=0; i<maxSize-5; i++)
cin >> data[i];
last = maxSize-5;
}

template<class T> SeqList<T>::output()
{
for(int i=0; i<maxSize; i++)
cout << data[i] << '\t';
cout << endl;
}

template<class T> SeqList<T>::insert(int i, T &x)
{
maxSize++;
int n=maxSize
for(; n>i; n--)
data[n] = data[n-1];
data[n] = x;
}

template<class T> SeqList<T>::remove(int i, T &x)
{
int n=i;
for(; n<maxSize; n++)
data[n] = data[n+1];
data[maxSize] = 0;
maxSize--;
}

template<class T> SeqList<T>::IsEmpty()
{
if(maxSize<0)
return true;
else
return false;
}

template<class T> SeqList<T>::IsFull()
{
if(maxSize>=10)
return true;
else
return false;
}

template<class T> SeqList<T>::getData(int i, T &x)
{
if(i>0 && i<=maxSize+1)
{
x = data[i-1];
return true;
}
else
return false;
}

template<class T> SeqList<T>::Locate(int i)
{
if(i>0 && i<=maxSize+1)
return data[i+1];
else
return 0;
}

#endif



1>c:\users\administrator\desktop\test\test\test.h(43): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\administrator\desktop\test\test\test.h(50): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\administrator\desktop\test\test\test.h(59): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\administrator\desktop\test\test\test.h(68): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\administrator\desktop\test\test\test.h(76): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\administrator\desktop\test\test\test.h(84): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\administrator\desktop\test\test\test.h(95): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\administrator\desktop\test\test\test.h(103): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
...全文
196 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
shexinwei 2010-11-03
  • 打赏
  • 举报
回复
声明中有返回值,但是实现中没有。

一般可以返回当前对象的引用,这样就可以将多个操作串接起来。
饭fan有引力 2010-11-03
  • 打赏
  • 举报
回复
已经解决了,忘了最基础的东西
dingshaofengbinbin 2010-11-03
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 qq120848369 的回复:]
你所有的成员函数定义都没有返回值。
[/Quote]
是啊
小楫轻舟 2010-11-03
  • 打赏
  • 举报
回复
拿最后一个举个例子

template<class T>
int SeqList<T>::Locate(int i) // 返回值int
{
if(i>0 && i<=maxSize+1)
return data[i+1]; // 这个好像是返回T
else
return 0;
}
qq120848369 2010-11-03
  • 打赏
  • 举报
回复
你所有的成员函数定义都没有返回值。

65,187

社区成员

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

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