Capture data from void

 

I want to capture data from void function

a void function may have int, bool or double value but may not return anything

Is it possible?

void VoidFunction() {
string a="I am Void";
Print(a);
}

If i try to capture

string a = VoidFunction();

It returns error expression of 'void' type is illegal

 
Hello. 
Goes through a reference. It will be more up-to-date and your function will remain in a void
 
This is nonsense.
string a = VoidFunction();
Same as if you wrote.
string a = ;
Void functions no return value.
 
William Roeder # :
Void functions no return value.

Not wrong at all.
Create the codes to respect the function typings. It’s an approach that makes sense.

My suggestion from the reference is worth its salt, even if sometimes it can make codes simpler.

 

@Arpit T and @Gerard Willia G J B M Dinh Sy :

I suggest you both read the documentation, and pay attention to William's post. Don't dismiss it.

Any function defined as "void", means that it has no return value. I repeat, no value is returned by a void function.

So, if you want a function to return a string, then declare it as returning a string and not as void.

string StringFunction() {
   return "I am string";
};
string a = StringFunction();

Another option is to pass the parameter by reference ...

void VoidFunction( string &sText ) {
   sText = "I am Void";
};
string a;
VoidFunction( a );
Print( a ); // outputs "I am Void"
Reason: