找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 758|回复: 4

重载 *出问题阿

[复制链接]
发表于 2009-11-3 02:18:39 | 显示全部楼层 |阅读模式 IP:江苏扬州
#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
谢谢
发表于 2009-11-3 02:18:41 | 显示全部楼层 IP:江苏扬州
我急用啊  
在编写string.h 头文件时候也出同样的错误
回复

使用道具 举报

发表于 2009-11-3 02:18:42 | 显示全部楼层 IP:江苏扬州
friend ostream & operator<<(ostream& ,const seqList&); //重载流输出运算符
friend istream & operator>>(istream&,seqList&); //重载流输入运算符
函数声明错了加个<Type>
回复

使用道具 举报

发表于 2009-11-3 02:18:43 | 显示全部楼层 IP:江苏扬州
在那里加<Type>
回复

使用道具 举报

发表于 2009-11-3 02:18:44 | 显示全部楼层 IP:江苏扬州
你自己定义的时候是对的,你看看你的定义部分吧
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-9-30 09:31 , Processed in 0.196784 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表