=运算符重载

1
2
3
4
5
6
7
8
9
10
Polynomial& Polynomial::operator=(const Polynomial& p){
if(this == &p) return *this;
delete[] coefficients;
size = p.size;
coefficients = new double[size];
for(int i = 0; i < size; i++){
coefficients[i] = p.coefficients[i];
}
return *this;
}

多项式类的赋值

要考虑 a = b = c 这种情况,所以返回reference类型