pbivens67 said:
I know how to return from a simple function, but I am working on how to do that using set.
I assume you felt uncertain because returning a single int feels simple, but returning an entire container of many objects feels complex and so there might be some difference?
But seems you have figured out the latter indeed just works.
However, there is another way to get data from a function, usually used if we need more than one result:
void ComputeUnionAndIntersection ( // no return
set<int> &union, set<int> &intersection, // outputs (becasue it's references, we can change the objects in the function and the caller will see those changes)
set<int> a, set<int> b) // inputs
{
//...
};
I guess you know that?
But maybe not, because then you could have used this to avoid the uncertainty. It's important. I think i do this as often as returning a single value.
This is also where const correctness becomes so helpful:
void ComputeUnionAndIntersection (
set<int> &union, set<int> &intersection,
const set<int> &a, const set<int> &b)
{
//...
};
Because now i can see which parameters are meant as inputs or outputs, to some degree at least.
No comments needed, and i made the inputs references too to avoid the copy, and it's still not confusingly looking like outputs.
But that just said for your info. Const correctness is purely optional, a matter of taste and not important.