input and print functions...

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?
Bumping. I still need an answer.
Why would it be void if you were going to input anything?

Why wouldn't it be? Perhaps it looks like this:

1
2
3
4
5
void input()
{
  cout << "Please give input" << endl;
  cin >> inputValue;
}
Last edited on
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.
closed account (zb0S216C)
JetX9 wrote:
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.

Wazzak
Frame, you would be half-correct. I have already learned classes, I am not just very proficient with them.

@Peter: As of right now, the function has nothing in it's definition, because I don't know what to put in it. Same with the print function.

In the beginning of the program, he tells me to test input and print.
1
2
3
4
void main()
{
	circle a;
	//   test input and print using a 


This is my first time encountering anything like this. Which is why I'm so confused.
void main()
That's not C++. Try
int main()
@Moschops:

That...really doesn't help me in the least.
Yes, it does. It helps you writing correct C++.
And calling a member function looks like this:

1
2
3
circle a;
a.input();
a.print(cout);
Last edited on
That...really doesn't help me in the least.


Oh, sorry. I thought you wanted to write C++ code. Carry on with whatever that Frankenlanguage you're using is :)
Topic archived. No new replies allowed.