Can't understand some syntax...

In the :

1
2
3
4
5
6
7
8
9
10
11
12
13
class polynomial{
	public:
		int coeff;
		int expo;
		class polynomial *next;
//Declaring the functions within the class
		polynomial input();
		polynomial output();
		polynomial addition(polynomial poly);
		polynomial multiplication(polynomial poly);
		polynomial subtraction(polynomial poly);
};
class polynomial x, y, z;


Can't understand :

class polynomial *next;

Do I need the word "class" here ?

class polynomial x, y, z;

What is this ? Why put it after the class declaration ?

Thanks in advance...
Do I need the word "class" here class polynomial *next; ?


No. It's like putting struct in front when you create an instance of a struct. It works, but it's not necessary.

What is this class polynomial x, y, z; ? Why put it after the class declaration ?

This is someone creating three instances of polynomial type; they are named x, y and z.

It's like this:
int x,y,z;
but instead of making ints, making polynomials. They could have done this instead:
polynomial x, y, z;

Last edited on
I am not sure but in C you put struct before declaring an object of that struct I am guessing you can do the same with classes but I know you do not have to you can just write polynomial x , y , and z. I may be wrong though.

Ooops Moschops beat me to it...
Last edited on
Thank you !

class polynomial x, y, z;

This line is outside int main() or any other function,so is it useless ?
Or is it global variables or such ?
Last edited on
This line is outside int main() or any other function,so is it useless ?


No. It create three instances of type polynomial outside the scope of everything. They are what is known as "global variables". They are bad and are to be avoided.
Last edited on
Yes of course,thanks guys,marked this as solved !
Topic archived. No new replies allowed.