hi!
I have a problem about "polynomial class ".when I Insert the firend function "operator<<" in the program.it doesn't run and have 5 error about
missing ";" in private member :"_degree" and missing ")" in first line(prototype)
of friend function "operator<<".
why this program have this ERRRS???!!! :(
can you help me??thanx for repling!!!
class poly {
friend ostream& operator<<(ostream&,const poly&);
//friend poly operator-(const poly&,const poly&);
//friend poly operator*(const poly&,const poly&);
//friend poly operator+(const poly&,const poly&);
//friend poly operator-(const poly&);
//friend list merge(iterator b1,iterator e1,iterator b2,iterator e2);
private:
long int _degree;
//void reduce();
public:
poly(double=0,unsigned=0);
double operator()(double) const;
long degreep() const;
unsigned termsp() const;
//static const poly ZERO; //p(x)=0
//static const poly ONE; //p(x)=1
//static const poly X; //p(x)=x
list _terms; //WARNING:IT IS TEMPORARY!!!
};
//------------------------------------------------------------------------------
poly::poly(double coef,unsigned exp){
if(coef==0.0){
_terms=list(0);
_degree= -1;
}
else
{_terms=list(1,term(coef,exp));
_degree=exp;
}
}
long max(long a,long b){
return (a>b?a:b);
}
//------------------------------------------------------------------------------
list merge(iterator b1,iterator e1,iterator b2,iterator e2){
list destlist;
while((b1!=e1)&&(b2!=e2))
{if((*b1)<(*b2))
{destlist.push_back(*b1);
b1++;
}
else
{destlist.push_back(*b2);
b2++;
}
}
while(b1!=e1)
{destlist.push_back(*b1);
b1++;
}
while(b2!=e2)
{destlist.push_back(*b2);
b2++;
}
return destlist;
}
//------------------------------------------------------------------------------
ostream& operator<<(ostream &ostr,const poly &p){
//if(p==poly::ZERO) return ostr<<0;
// iterator itr=p._terms.begin();
// ostr<<*itr++;
// while(itr!=p._terms.end())
// if (((*itr)._coef)<0) ostr<<"-"<<abs(*itr++);
// else ostr<<"+"<<*itr++;
// return ostr;
}
//------------------------------------------------------------------------------
//poly operator+(const poly& p1,const poly& p2){
// poly p;
// p._degree=max(p1._degree,p2._degree);
// p._terms=list(p1._terms.size()+p2._terms.size());
// merge(p1._terms.begin(),p1._terms.end(),p2._terms.begin(),p2._terms.end());
// p.reduce();
// return p;
//}
//------------------------------------------------------------------------------
//poly operator*(const poly &p1,const poly &p2){
// poly p;
// p._degree=p1._degree+p2._degree;
// for(iterator it1=p._terms.begin();it1!=p.terms._end;it1++)
// for(iterator it2=p._terms.begin();it2!=p.terms._end;it2++){
// double coef=(*it1)._coef * (*it2)._coef;
// unsigned exp=(*it2)._coef * (*it2)._coef;
// iterator it=p._terms.begin();
// for( ;it!=p._terms.end();it++)
// if ((*it)._exp <=exp) break;
// if((*it)._exp == exp)
// (*it)._coef +=coef;
// else
// p._terms.insert(it,term(coef,exp));
// }
// p.reduce();
// return p;
// }
//------------------------------------------------------------------------------
//double poly::operator()(double x) const{
//
// iterator it=_terms.begin();
// if(it==_terms.end()) return 0;
//
// unsigned e1=(*it)._exp;
// double y=(*it)._coef;
// while(++it!=_terms.end())
// {unsigned e2=(*it)._exp;
// y*=pow(x,(e1-e2));
// y+=(*it)._coef;
// e1=e2;
// }
// return y*pow(x,e1);
// }