In addition to the other answers, which are technically correct: if your really need to return something, using a void function makes no sense at all. After all, what is the return parameter for?!
I would somehow understand if you already have one return parameter and then need to add something else to return. The answer would be 1) return second value using a parameter by reference; 2) using pointer passed by value and changing the pointed object in the code of your function (as it is done on C); 3) using return parameter, but with a different type such as
class
or
struct
, so all your return data would be passed in the members of the
class
/
struct
.
But no, you're asking about returning something from a void function. This is really an oxymoron. In practice, there is no situation when it can be needed.
[EDIT]
Example:
void func1(int &value){ value = some_value; }
int func1(){ return some_value; }
Same thing with any other parameter type. With reference or pointer type a caution should be used: the object should exist even when an instance of the class is destroyed, but this is exactly same thing as with passing the our parameter by reference. Read also on the concept of
l-value in any C++ manual.
[END EDIT]
—SA