您好,我已经重载了插入和提取运算符。当我运行我的程序时,尽管提取正在将值放入类中,但插入似乎没有输出值。似乎实例的插入视图中没有任何值。
主要的
/ Input Poly
cout << "Input p1: " << endl;
Polynomial P1;
cin >> P1;
// Output Poly
cout << "p1(x) = " << P1 << '\n' << endl;
类功能
//Insertion
ostream& operator<<(ostream& os, Polynomial Poly){
for (int i=0; i < Poly.polyNum; i++) {
os << Poly.poly[i] << " x^" << i;
if(i != Poly.polyNum - 1){
os << " + ";
}
}
return os;
}
//Extraction
istream& operator>>(istream& is, Polynomial Poly){
int numP = 0;
int * tempP;
is >> numP;
tempP = new int [numP+1];
for (int i=0; i < numP; i++) {
is >> tempP[i];
}
Poly.polyNum = numP;
Poly.poly = new int[Poly.polyNum +1];
for (int i=0; i < Poly.polyNum; i++) {
Poly.poly[i] = tempP[i];
}
return is;
}