这是一段从别处拷来的一元多项式的代码,请大虾看一下
#include<iostream.h>
#include<list>
struct Term
{
float coef;
int exp_x,exp_y;
Term(float c,int e1,int e2){coef=c;exp_x=e1;exp_y=e2;}
Term(){}
friend int operator==(const Term & L,const Term & T)//项序比较,按x的升幂排列
{
return (L.exp_x==T.exp_x)&&(L.exp_y==T.exp_y);
}
friend int operator >(const Term & L,const Term & T)
{
return ((L.exp_x>T.exp_x)||(L.exp_x==T.exp_x)&&(L.exp_y>T.exp_y));
}
friend int operator <(const Term & L,const Term & T)
{
return ((L.exp_x<T.exp_x)||(L.exp_x==T.exp_x)&&(L.exp_y<T.exp_y));
}
friend Term & operator+=(Term & L,const Term & T)//幂指数对应相同,则系数相加
{
L.coef+=T.coef; return L;
}
friend istream & operator>>(istream & is,Term & T);
friend ostream & operator<<(ostream & os,const Term & T);
friend char compare(const Term & P,const Term & T);
friend Is_Empty(const Term & T){return !T.coef;}
};
char compare(const Term & P,const Term & T)
{
if(P==T) return'=';
else if(P<T) return '<';
else return'>';
}
istream & operator>>(istream & is,Term & T)
{
cout<<"Please input a coefficient!\n";
is>>T.coef;
cout<<"Please input the power of x!\n";
is>>T.exp_x;
cout<<"Please input the power of y!\n";
is>>T.exp_y;
return is;
}
ostream & operator<<(ostream & os,const Term & T)
{
if(T.coef>0) os<<'+';
os<<T.coef<<"x^"<<T.exp_x<<"y^"<<T.exp_y;
return os;
}
template<class ElemType>
class Polynomial
{
public:
Polynomial(const ElemType & P){Stop_flag=P;}
Polynomial(){}
~Polynomial(){}
Polynomial & operator=(const Polynomial & T);
Polynomial & operator+(const Polynomial & T);
friend istream & operator>>(istream & is,Polynomial<ElemType> & T);
friend ostream & operator<<(ostream & os,const Polynomial<ElemType> & T);
private:
List <ElemType> poly;//???????????????????????
//Term<T>*
ElemType Stop_flag;//用于判断多项式结束
};
template<class ElemType>
istream & operator>>(istream & is,Polynomial<ElemType> & T)
{
ElemType elem;
ListItr<ElemType>Itr(T.poly);
cout<<"Creat a Polynomial!\n";
cout<<"Please input coeffcient and power one by one!\n"
while(cin>>elem,!equal_stop(elem,T.Stop_lag)) Itr.Insert(elem);
return is;
}
编译的时候这样报错:
syntax error :missing ';' before '<'
请问:这是不是List引起的,或者应该怎么改动,
我对这一块C++的内容很不了解