This is compiling fine and producing the desired result, i.e. plots the sin(x) curve. What I want to understand is this piece of code: "class M1 :public MatPlot{..." As I see it you are defining a new class M1 with the already defined class MatPlot as a public member in the class. If that is correct, is there a way where I can define class M1 in a conventional way like
1 2 3 4 5 6
class M1 {
public:
int z;
MatPlot{ ...
}mp;
PS: . My end objective is to use an array of doubles I have and use this code to pplot that array.
Thanks to booradley I understand it better now. I should've read the inheritances before. Apologies.
i understood the code and made changes so that I can pass an array of doubles and plot that rather than some pre-defined function sin(x).
This throws a compile error "IntelliSense: argument of type "void" is incompatible with parameter of type "void (*)()". What does this mean? Note that this compilation error comes from the line: "glutDisplayFunc( display1(y));"
The function glutDisplayFunc is probably expecting to be passed a pointer to a function as a parameter. Look at glutReshapeFunc on the next line. You're passing the name of the function (which acts as a pointer to the function itself). So the line the compiler is complaining about should probably look like this: glutDisplayFunc( display1 );
glutDisplayFunc expects a pointer to a function. On line 26 you aren't giving it a pointer. You're giving it the result of callingdisplay1 with argument y. The return type of display1 is void. Thus the error message.
Notice that the type of the pointer expected is void (*)() which is a pointer to a function that takes no parameters. You cannot feed it the address of display1 without the compiler barfing. You'll need to take a different approach.