| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 493 人关注过本帖
标题:重载 >出问题阿
只看楼主 加入收藏
winey
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-2-16
收藏
 问题点数:0 回复次数:4 
重载 >出问题阿

#include<iostream.h>

template <class Type>
class seqList
{
friend ostream & operator<<(ostream& ,const seqList&); //重载流输出运算符
friend istream & operator>>(istream&,seqList&); //重载流输入运算符
public:
seqList ( int MaxSize = defaultSize );

~seqList ( ) { delete [ ] data; }

int length ( ) const { return last+1; }

int find ( Type & x ) const;

int isIn ( Type & x );

int insert ( Type & x, int i );

int remove ( Type & x );

int next ( Type & x ) ;

int prior ( Type & x ) ;

int isEmpty ( ) { return last ==-1; }

int isFull ( ) { return last == MaxSize-1; }

Type get ( int i )
{
return i < 0 || i > last?NULL : data[i];
}

private:
Type *data; //顺序表存储数组
int maxSize; //最大允许长度
int last; //当前最后元素下标
};
////////////////////////////////////////////////////////////
#include<iostream.h>
#include"list.h"

template <class Type>

seqList<Type> :: seqList ( int sz )
{ //构造函数
if (sz>0)
{
maxSize = sz;
last = -1;

data = new Type[maxSize];

if ( data == NULL )
{
maxSize = 0;
last = -1;
return;
}
}
}

template <class Type>
int seqList<Type>::find ( Type & x ) const
{
//搜索函数:在表中从前向后顺序查找 x
int i = 0;
while ( i <= last && data[i] != x )
i++;
if ( i > last )
return -1;
else
return i;
}

template <class Type>
int seqList<Type>::insert ( Type & x, int i )
{//在表中第 i 个位置插入新元素 x
if ( i < 0 || i > last+1 || last == maxSize-1 )
return 0; //插入不成功
else
{
last++;

for ( int j = last; j > i; j-- )
data[j] = data[j -1];

data[i] = x;
return 1; //插入成功
}
}

template <class Type>
int seqList<Type>::remove ( Type & x )
{//在表中删除已有元素 x
int i = find (x); //在表中搜索 x

if ( i >= 0 )
{
last-- ;

for ( int j = i; j <= last; j++ )
data[j] = data[j+1];
return 1; //成功删除
}

return 0; //表中没有 x
}

template <class Type>
istream&operator>>(istream& input,seqList<Type> &a)//重载>>函数的实现
{
for(int i=0;i<a.maxSize;i++)
input>>a.date[i];
return input;
}

template <class Type>
ostream& operator<<(ostream &output,const seqList<Type> &a)//重载<<函数的实现
{
int i=0;
for(i=0;i<a.maxSize;i++)
{
output<<" "<<a.date[i];
}
output<<endl;
return output;
}
//////////////////////////////////////////////
#include<iostream.h>
#include"list.h"

template <class Type>
void Intersection ( seqList<Type> & LA,seqList<Type> & LB )
{
int i=0,j=0;
Type temp;
aLen=LA.length();
for(i=0;i<aLen;i++)
{
temp=A.get(i);
bLen=LB.length();
if(i==0)
{
LB.insert(temp,i);
}
else
{
for(j=0;j<bLen;)
{
if(temp>LB.get(j))
j++;
else
{
LB.insert(temp,j);
break;
}
}
}
}
}

template <class Type>
int main()
{
seqList A(5),B(5);

cout<<"please enter five number to initial A:\n";
cin>>A;

cout<<A<<endl;
Intersection (A,B);

cout<<"B:"<<B<<endl;

return 1;

}


为什么通不过阿 模版去掉就好了
提示错误
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/list.exe : fatal error LNK1120: 1 unresolved externals
谢谢

搜索更多相关主题的帖子: 重载 
2006-05-24 12:47
winey
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-2-16
收藏
得分:0 
我急用啊  
在编写string.h 头文件时候也出同样的错误
2006-05-24 12:49
wfpb
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2188
专家分:0
注 册:2006-4-2
收藏
得分:0 
friend ostream & operator<<(ostream& ,const seqList&); //重载流输出运算符
friend istream & operator>>(istream&,seqList&); //重载流输入运算符
函数声明错了加个<Type>

[glow=255,red,2]wfpb的部落格[/glow] 学习成为生活的重要组成部分!
2006-05-24 13:01
winey
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-2-16
收藏
得分:0 

在那里加<Type>

2006-05-24 13:17
wfpb
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2188
专家分:0
注 册:2006-4-2
收藏
得分:0 

你自己定义的时候是对的,你看看你的定义部分吧


[glow=255,red,2]wfpb的部落格[/glow] 学习成为生活的重要组成部分!
2006-05-24 13:18
快速回复:重载 >出问题阿
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021045 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved