View Full Version : c++ void returning vs other kinds

09-06-2008, 08:36 AM
Just wondering:

if you set up a void function to do something like:

void blah(int x);
{ return x; }

Why can't you use it in a situation like:

cout << "this is x" << blah(input) << endl;

I know if "blah" is an int function, int blah(whatever), it'll work, but the void is returning the same thing; why does this work/not work the way it does? Thanks

09-06-2008, 10:28 AM
The keyword void/int before function name is specifying the type of the value to be returned. A function with void type is supposed to return nothing!

09-06-2008, 11:58 AM
Ah, more than I knew before, thanks. But then, if I were to put a cout statement in there, like:

void blah()
{ cout << "hello" << endl; }

it'd return a statement to the screen "hello" just fine, so why when it's returning just a number why you can't simply use it as a number. Is it considered something like a string in that case?

09-06-2008, 12:08 PM
void blah()
{ cout << "hello" << endl; } It's not returning or trying to return anything. It just echoes a "hello", when called.

09-06-2008, 06:46 PM
More specifically, in that case blah() writes "hello" to the cout stream; but that isn't returning anything.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum