| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 455 人关注过本帖
标题:这个错误要怎么解决
只看楼主 加入收藏
偶成
Rank: 1
等 级:新手上路
帖 子:90
专家分:0
注 册:2006-3-4
收藏
 问题点数:0 回复次数:0 
这个错误要怎么解决

这个程序的错误是加了最后一行 cout<<dq; 就跳出错误,没有那行就没问题的.
#include "stdafx.h"
#include <iostream>
#include <cassert>
using namespace std;

template<class type>
struct nodetype
{
type info;
nodetype<type> *link;
};
template<class type>
class linklist{
friend ostream& operator<<(ostream&,const linklist<type>&);//重载<<运算符
public:
const linklist<type>& operator=(const linklist<type>&);//重载=运算符
void initializelist();//初始化函数
bool isempty();//链表是否为空
int length();//返回链表的节点数
void destorylist();//删除链表所有节点,头尾指针设置为0
type front();//返回链表第一个节点元素
type back();//返回链表最后一个节点元素
bool search(const type& searchtitem);//确定某个元素是否在链表中
void insertfirst(const type& newitem);//在表前插入节点
void insertlast(const type& newitem);//在表后插入节点
void deletenode(const type& deleteitem);//删除表中的某个点
linklist();//默认构造函数
linklist(const linklist<type>& otherlist);//拷贝函数
~linklist();//析构函数
protected:
int count; //链表的节点数
nodetype<type> *first; //链表头指针
nodetype<type> *last; //链表尾指针
private:
void copylist(const linklist<type>& otherlist);//复制表otherlist给表
};

template<class type>
bool linklist<type>::isempty(){return (first==NULL);}//定义函数判断链表是否为空

template<class type>
linklist<type>::linklist(){//定义默认构造函数
first=NULL;
last=NULL;
count=0;
}

template<class type>
void linklist<type>::destorylist(){//定义函数,清空链表
nodetype<type> *temp;
while(first!=NULL){
temp=first;
first=first->link;
delete temp;
}
last=NULL;
count=0;
}
template<class type>
void linklist<type>::initializelist(){destorylist();}//定义函数,初始化链表

template<class type>
ostream& operator<<(ostream& out,const linklist<type>& list){//重载运算符<<函数
nodetype<type> *current;
current=list.first;
while(current != NULL){
out<<current->info<<" ";
current=current->link;
}
return out;
}

template<class type>
int linklist<type>::length(){return count;}//定义函数,返回链表节点数

template<class type>
type linklist<type>::front(){//定义函数,返回第一个节点
assert(last != NULL);
return first->info;
}

template<class type>
type linklist<type>::back(){//定义函数,返回最后一个节点
assert(last != NULL);
return last->info;
}

template<class type>
bool linklist<type>::search(const type& searchitem){//定义函数,查找一个元素是否在表中
nodetype<type> *current;
bool found;
current=first;
found=false;
while(current!=NULL && !found)
if(current->info==searchitem)
found=true;
else
current=current->link;
return found;
}

template<class type>
void linklist<type>::insertfirst(const type& newitem){//定义函数,在表头部插入节点
nodetype<type> *newnode;
newnode=new nodetype<type>;
assert(newnode != NULL);
newnode->info=newitem;
newnode->link=first;
first=newnode;
count++;
if(last==NULL)
last=newnode;
}

template<class type>
void linklist<type>::insertlast(const type& newitem){//定义函数,在表尾部插入节点
nodetype<type> *newnode;
newnode=new nodetype<type>;
assert(newnode != NULL);
newnode->info=newitem;
newnode->link=NULL;
if(first==NULL){
first=newnode;
last=newnode;
count++;
}
else{
last->link=newnode;
last=newnode;
count++;
}
}

template<class type>
void linklist<type>::deletenode(const type& deleteitem){//定义函数,删除表中某个节点
nodetype<type> *current;
nodetype<type> *trailcurrent;
bool found;
if(first==NULL)
cerr<<"cannot delete from an empty list.\n";
else{
if(first->info==deleteitem){
current=first;
first=first->link;
count--;
if(first==NULL)
last=NULL;
delete current;

}
else{
found=false;
trailcurrent=first;
current=first->link;
while(current!=null && !found){
if(current->info!=deleteitem){
trailcurrent=current;
current=current->link;
}
else
found=true;
}
if(found)
{
trailcurrent->link=current->link;
count--;
if(last==current)
last=trailcurrent;
delete current;
}
else
cout<<"item to be deleted is not in the list."<<endl;
}
}
}

template<class type>
void linklist<type>::copylist(const linklist<type>& otherlist){//定义函数,复制已知表给当前表
nodetype<type> *newnode;
nodetype<type> *current;
if(first!=NULL)
destorylist();
if(otherlist.first==NULL){
first=NULL;
last=NULL;
count=0;
}
else{
current=otherlist.first;
count=otherlist.count;
first=new nodetype<type>;
assert(first!=NULL);
first->info=current->info;
first->link=NULL;
last=first;
current=current->link;
while(current!=NULL){
newnode=new nodetype<type>;
assert(newnode!=NULL);
newnode->info=current->info;
newnode->link=NULL;
last->link=newnode;
last=newnode;
current=current->link;
}
}
}

template<class type>
linklist<type>::~linklist(){destorylist();}//定义析构函数

template<class type>
linklist<type>::linklist(const linklist<type>& otherlist){//定义复制构造函数
first=NULL;
copylist(otherlist);
}

template<class type>
const linklist<type>& linklist<type>::operator=(const linklist<type>& otherlist){//重载运算符=函数
if(this!=&otherlist)
copylist(otherlist);
return *this;
}


int _tmain(int argc, _TCHAR* argv[])
{
linklist<int> dq,dq2;
dq.insertfirst(30);
dq.insertfirst(50);
dq.insertfirst(100);
dq.insertfirst(80);
dq.insertlast(250);
dq2=dq;
cout<<dq;
return 0;
}

错误提示是这样的:
错误 1 error LNK2019: 无法解析的外部符号 "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class linklist<int> const &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@ABV?$linklist@H@@@Z),该符号在函数 _wmain 中被引用 lianxi.obj
错误 2 fatal error LNK1120: 1 个无法解析的外部命令 E:\Documents and Settings\Visual Studio 2005\Projects\lianxi\Debug\lianxi.exe 1

搜索更多相关主题的帖子: include public friend 
2006-06-11 09:08
快速回复:这个错误要怎么解决
数据加载中...
 
   



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

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