I solved my problem in the following way... I changed my constructor and made it look like that in the class definition:
polynomial(int d,int test=0);
and this is its code:
polynomial::polynomial(int d,int test){
int i;
degree=d;
if(test==0){
coefs=(float *)malloc((d+1)*sizeof(float));
cout<<"Create a polynomial of degree "<<d<<"\n";
for (i=d;i>0;i--){
cout<<"The coefficient of x^"<<i<<" is : ";
cin>>coefs[i];
cout<<"\n";
}
cout<<"The constant is : ";
cin>>coefs[0];
cout<<"\n";
cout<<"The polynomial is created\n";
}
else{
coefs=(float *)malloc((d+1)*sizeof(float));
for (i=d;i>=0;i--){
coefs[i]=0;
}
}
}
then the function that was causing the problem was made into this:
void polynomial::operator==(polynomial P){
int i;
for(i=0;i<=degree;i++){
coefs[i]=P.coefs[i];
}
}
and with accordingly adapting small parts of my code,I was able to call P[x] without destroying my polynomial.If you have any question,please ask