Which one is better if I have to return a string as well as an array from a function.
- Create a structure containing string and array, populate that and return the instance of that structure.
Consider I have to send string "status" and an array "ids".
struct ReturnValues {
string status;
int ids[10];
};
use it as:
ReturnValues returnValues;
returnValues = func();
Consider that func() returns the object of ReturnValues
- Pass one of them as referenced variable and return the other.
As:
int ids[10];
string status = func(ids);
Consider that func takes ids as referenced variable
string func(int& ids) {
//Some code
return status;
}
- Pass both as referenced variables returning void.
As:
int ids[10];
string status;
func(ids, status);
Consider that func takes ids and status as referenced variables
void func(int& ids, string& status) {
//some code;
}