Okay. On this particular assignment, we have member functions defined as const. One of them is called print, and looks like this:
void print(ostream &w) const;
as the definition. What confuses me is how would I use this? He's telling us to output answers with it, but all i can see being used with this is cout and nothing else.
There is also this input function that is giving me headaches...
void input(void);
Why would it be void if you were going to input anything?
The const after the function name means that the object that the function belongs to will will be treated as a const. That means you cannot modify any of the member variables of the object. This makes it possible to call the print function even if the object is const. It is generally a good idea to mark all functions that doesn't modify the object as const.
void input(void); is exactly the same as void input(); so there is no reason to use void like that. Some people do it anyway, probably because they have a C background. In C there is a difference, in C++ there isn't.
but all i can see being used with this is cout and nothing else.
That's what the parameter is for. The parameter allows the calling function to specify which stream to use when outputting. I assume you're learning classes, and that you know what const does in this context.
JetX9 wrote:
There is also this input function that is giving me headaches...
void input(void);
What's the pre-defined input stream? Since there's no way of specifying which stream to use, it must assume another accessible stream.