Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have the below function.

void func(ENUM retCode, std::string name);

I want to return retCode and name from the function.
How to do this?

What I have tried:

I have tried to return value(s) from a void function.
Posted
Updated 29-Jan-21 7:41am
Comments
jeron1 29-Jan-21 12:02pm    
Then they have to passed by reference.
Richard MacCutchan 29-Jan-21 12:12pm    
Are the returned values different from the ones you are passing in?
Member 15025528 29-Jan-21 12:21pm    
Thanks for your reply Richard.
Richard MacCutchan 29-Jan-21 12:29pm    
What does that mean?
Member 15025528 29-Jan-21 12:37pm    
if we have string as return type then this is specific to string only.
But in real environment, we no need to specific a particular data type.

 
Share this answer
 
v2
Quote:
void func(ENUM retCode, std::string name);

What's wrong with
C++
ENUM func(std::string name);
?
If you really need to return a value then return it.

As an alternative you could pass an item by reference (see, for instance C++ Functions - Pass By Reference[^])

Another, rather ugly, alternative is changing the value of a global variable.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900