I found a begginers c++ challenge I wanted to try. However, the following code is saying that it contains erros when I compile it. If I try to take 1 line at a time, it exits in the first class definition at the end... I have no idea what's wrong :)
#include <iostream>
using namespace std;
class Polynomial {
int a, b, c, functionValue;
public:
Polynomial (int, int, int);
static void functionValue(Polynomial);
};
Polynomial::Polynomial (int x, int y, int z) {
a = x;
b = y;
c = z;
}
void Polynomial::functionValue(Polynomial x) {
for (int i = 0; i < 5; i++) {
x.functionValue = x.a * pow(i, 2) + x.b * i + x.c;
cout << "The value of the function for x = "
<< i << " is " << x.functionValue;
}
}
int main () {
Polynomial poly (2, 3, 5);
Polynomial::functionValue(poly);
system("pause");
return 0;
}
I don't know why the formatting is so poor. Here is a pastebin link.
(Edit: My fault, I edited over a previous edit and accidentally removed these - BoBTFish)
Compiler errors:
'Polynomial::functionValue' : redefinition; previous definition was 'data member' 'see declaration of 'Polynomial::functionValue'
'Polynomial::functionValue' : not a function' 'illegal reference to non-static member 'Polynomial::functionValue'
Thanks in advance.