0

I'm trying to create an overload of the "+" within my program to add a private constant value to an already establish polynomial, but the last portion of my code comes out with the following error:

`Error 1 error C2677: binary '+=' : no global operator found which takes type 'Polynomial' (or there is no acceptable conversion) h:\documents\baker school\visual basic\polynomialmagic\polynomialclass.cpp 131 PolynomialMagic`

I've tried switching out "+=" for "+" and I get the same error...what am I doing wrong?

```
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <cmath>
using namespace std;
class Polynomial
{
public:
void Polynomial1 ();
void Polynomial2 ();
int Degree;
int *coef1, *coef2;
int *power1, *power2;
int SoloNumber1;
private:
static const int ConstValue = 5;
};
int operator +(Polynomial &Poly1, Polynomial ConstValue);
int main()
{
int PolyChoice;
Polynomial Poly1,Poly2;
cout << "How many Polynomials Do You Want to Use: 1 or 2? ";
cin >> PolyChoice;
if (PolyChoice == 1)
{
Poly1.Polynomial1();
cout << endl;
}
if (PolyChoice == 2)
{
Poly1.Polynomial1();
cout << endl;
Poly2.Polynomial2();
}
return 0;
}
void Polynomial::Polynomial1()
{
int i,n;
cout << "What Degree Polynomial: ";
cin >> i;
coef1 = new (nothrow) int[i];
power1 = new (nothrow) int[i];
for (n=0; n<(i); n++)
{
cout << "Enter Coefficient #: ";
cin >> coef1[n];
}
for (n=0;n<=(i);n++)
{
power1[n]= n+1;
}
cout << "Enter Solo Numbers (Those Without A Corresponding x): ";
cin >> SoloNumber1;
cout << "Polynomial selected is: ";
for (n=0;n<i;n++)
{
if(n != (i-1))
cout << coef1[n] << "x^(" << power1[n] << ")" << " + ";
else
cout << coef1[n] << "x^(" << power1[n] << ") + " << SoloNumber1;
}
}
void Polynomial::Polynomial2()
{
int h,j, SoloNumber2;
cout << "What Degree Polynomial: ";
cin >> h;
coef2 = new (nothrow) int[h];
power2 = new (nothrow) int[h];
for (j=0; j<h; j++)
{
cout << "Enter Coefficient #: ";
cin >> coef2[j];
}
for (j=0;j<h;j++)
{
power2[j]= j;
}
cout << "Enter Solo Numbers (Those Without A Corresponding x): ";
cin >> SoloNumber2;
cout << "Polynomial selected is: ";
for (j=0;j<h;j++)
{
if(j != (h-1))
cout << coef2[j] << "x^(" << power2[j] << ")" << "+";
else
cout << coef2[j] << "x^(" << power2[j] << ") + " << SoloNumber2 << endl;
}
}
int operator +(Polynomial Poly1, Polynomial &ConstValue)
{
int NewValue;
NewValue += Poly1.SoloNumber1;
NewValue += ConstValue;
return NewValue;
}
```

*Edited 6 Years Ago by PDB1982*: n/a