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);
阅读(2982) | 评论(3) | 转发(0) |