I am trying to make a class for Polynomial which will take input of the max degree of the polynomial and then accordingly, will set the maximum array size and will take inputs for all the powers.
I made a test program and overloaded the operator, however, I am getting two errors,
First,
"illegal reference to non-static member 'Polynomial::size' (Line 21, Line 22, Line 25, Line 27)"
Second,
"'Polynomial::size': non-standard syntax; use '&' to create a pointer to member (Line 25, Line 27)"
Now, what I understand by the first error is this that I have to make int size static.. But I don't want to that as every object of Polynomial will have a different size, so how can I tackle this issue?
And I don't understand what is it the second error is saying? :/
Can anyone help resolving these issues? Thank you!
Here is my test code for now,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#include <iostream>
using namespace std;
class Polynomial
{
private:
int size;
float *po, *in;
public:
Polynomial()
{
po = NULL;
in = NULL;
size = 0;
}
friend istream &operator >> (istream &inp, Polynomial &r)
{
cout << "Enter Max power variable: ";
int max;
inp >> max;
r.size = max + 1;
r.po = new float[size];
r.in = new float[size];
for (int i = 0; i < r.size; i++)
{
cout << "Enter Co-efficient for power(" << size - 1 << "): ";
inp >> r.in[i];
r.po[size - (i + 1)] = size - 1;
}
}
friend ostream &operator << (ostream &out, Polynomial &r)
{
for (int i = 0; i < r.size; i++)
{
out << r.in[i];
if (i == 0)
continue;
if (i == 1)
cout << "x";
else
cout << "x^" << r.po[i];
}
}
};
int main()
{
Polynomial r;
cout << endl << endl;
cout << r;
cout << endl;
system("pause");
return 0;
}
|