首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

请教这是什么东东

2012-02-26 
请问这是什么错误我在编数据结构单链表类时,编译出现如下错误提示:E:\vc++\数据结构c++程序\单链表\linkli

请问这是什么错误
我在编数据结构单链表类时,编译出现如下错误提示:
E:\vc++\数据结构c++程序\单链表\linklist.cpp(148)   :   error   C2244:   'linklist <type> ::GetCurrent '   :   unable   to   resolve   function   overload
Error   executing   cl.exe.
以下是源程序:
////////////////////////////////////////////////////////////////////////
//linklist.h
#ifndef   linklist_h
#define   linklist_h
#include   "node.h "
template <class   type> class   linklist
{
private:
node <type>   *head;//指向头结点的头指针
node <type>   *pcurrent;//当前结点指针
public:
//构造函数和析构函数
linklist(void);//构造函数
~linklist(void);//析构函数
//表操作的成员函数
int   Length(void)const;//返回链表的数据结点个数
type   GetCurrent()const;//返回当前结点的数据值
node <type>   *Locate(type&   x);//搜索数据值为x的结点,并成为当前结点
void   InsertBefore(const   type&   x);//将x插在表中当前结点之前,并成为当前结点
void   InsertAfter(const   type&   x);//将x插在表中当前结点之后,并成为当前结点
type   DeleteCurrent();//删除当前结点,设填补者为当前结点
int   IsEmpty(void)const;//表空否,空返回1,否则返回0
void   Clear(void);//把表清空
//遍历链表的成员函数
node <type>   *Reset(int   i);//使第i个结点为当前结点
node <type>   *Next(void);//使当前结点指针指向下一个结点
int   EndofList(void)const;//是否链表尾,是返回1,否则返回0
void   FreeList(void);//释放链表
};
#endif
//node.h
#ifndef   node_h
#define   node_h
//#include   "linklist.h "
template <class   type> class   linklist;
template <class   type> class   node
{
friend   class   linklist;
private:
node <type>   *next;//链指针域
public:
type   data;//数据域,定义为公有成员,使用方便
node(node <type>   *pnext=NULL);//构造函数,用于构造头结点
node(const   type&   item,node <type>   *pnext=NULL);//构造函数,用于构造非头结点
void   setnext(node <type>   *p){next=p;}//修改结点的next域
void   setdata(type   x){data=x;}
~node(){}//析构函数,为空
};
#endif
//////////////////////////////////////////////////////////////////////////
//linklist.cpp
#include <iostream.h>
#include "linklist.h "
template <class   type> //取当前结点的数据值
type   linklist <type> ::GetCurrent()
{
if(pcurrent==head||pcurrent==NULL)
{
cout < < "未取到数据值! " < <endl;//因空表或当前指针为空,未取到数据的值
exit(1);
}
type   data1=pcurrent-> data;
return   data1;//返回当前结点的数据值
}
/////////////////////////////////////////////////////////////////
type   linklist <type> ::GetCurrent()是出问题的成员函数定义

[解决办法]
type GetCurrent()const;//返回当前结点的数据值
type linklist <type> ::GetCurrent()
一个有const,一个没有,所以报重载了,在后面加上就可以了
type linklist <type> ::GetCurrent() const
[解决办法]
改方法的声明和实现不是一个,看看是不是遗漏了什么东西

热点排行