Chinaunix首页 | 论坛 | 博客
  • 博客访问: 213107
  • 博文数量: 35
  • 博客积分: 1480
  • 博客等级: 上尉
  • 技术积分: 390
  • 用 户 组: 普通用户
  • 注册时间: 2007-11-14 14:27
文章分类

全部博文(35)

文章存档

2008年(35)

我的朋友

分类: C/C++

2008-04-09 08:20:57

1.程序运行时错误
大意:0xXXXXX这块内存不允许你读或者没有分配而你去读了
错误代码:程序的析构函数 
void Clear()
 {
  for(Node* temp=head;head!=NULL;head=head->link)
  {
   temp=head;
   delete temp;
  }
  delete head;
 }
改成如下后错误消失
void Clear()
 {
  for(Node* temp=head;temp!=NULL;temp=head)
  {
   head=head->link;
   delete temp;
  }
  delete head;
 }
2:
template
ostream& operator<<(ostream& out,const Polynomimal& x)
{
x.Output(out);
return out;
}
template
istream operator >>(istream& in,Polynominal& x)
{
x.Input(in);
return in;
}
 
error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
error C2143: 语法错误 : 缺少“,”(在“<”的前面)
 
改成如下后错误消失
 
ostream& operator<<(ostream& out,const Polynominal& x)
 
原因:单词写错,Polynominal写成了Polynomimal
 
3:
1>Polynominal.obj : error LNK2001: 无法解析的外部符号 "class std::basic_ostream > & __cdecl operator<<(class std::basic_ostream > &,class Polynominal const &)" ()
1>Polynominal.obj : error LNK2001: 无法解析的外部符号 "class std::basic_istream > & __cdecl operator>>(class std::basic_istream > &,class Polynominal &)" ()
1>D:\My Documents\Visual Studio 2008\Projects\MyLib\Debug\MyLib.exe : fatal error LNK1120: 2 个无法解析的外部命令
 
错误原因,友元重载函数在类外定义时写法不对,将
 friend std::ostream& operator << (std::ostream&,const Polynominal &x); 
 friend std::istream& operator >> (std::istream& in,Polynominal &x);
改成
 friend std::ostream& operator << <>(std::ostream&,const Polynominal &x); 
 friend std::istream& operator >> <>(std::istream& in,Polynominal &x);
阅读(2955) | 评论(3) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-04-22 10:13:24

得益于作者的提示,解决了我的疑难,衷心感谢!!

linfengfeiye2008-09-02 19:14:28

temp!=NULL,head!=NULL

chinaunix网友2008-09-02 15:54:37

void Clear() { for(Node* temp=head;temp!=NULL;temp=head) { head=head->link; delete temp; } delete head; } 瞎扯 delete NULL;也正确?