I have a question,
Is it possible to have 2 variables be set to 2 variables that are returned in a function, Its hard to explain.
So I have 2 variables, that I want to set there values from 1 function.
For example
string name;
int age;
The Function is something like this
string information(string name, int age) {
name = "name";
age = rand()%50+1;
return name;
return age;
}
Could you do something like
name, age = information(name, age);
Having 2 separate variables get values from one function
and you can use typedef (simple array, etc) or struct (mixed types) or a pointer/vector/many things to create a custom return type and pull it out of that.
#include "CMultipleReturn.h"
const CMultipleReturn FunctionThatDoesSomething();
int main()
{
CMultipleReturn cReturn;
cReturn=FuctionThatDoesSomething();
printf("The first value is %i\nThe second value is %i",
cRetuen.GetReturnOne(),
cReturn.GetReturnTwo());
}
const CMultipleReturn FuctionThatDoesSomething()
{
int iFirstValue{0};
int iSecondValue{0};
...//Code follows which put something useful in to these two integers.
return CMultipleReturn{iFirstValue, iSecondValue};
}
It would be relatively easy--I think!--to use templates and make the same class usable with any return data type you wanted. As I mentioned in another thread I am still finding my feet again in the newest versions of the language, so apologies for any obvious errors. That is just a class I was able to literally copy and paste from the programme I currently have open in front of me and am pottering about with right now.