question about a string set

Is it possible to pass a string set into a function or return a string set from a function, like.


void (set<string> stringSet, int m);

is that how it would go or would you have to do something different?

And/Or how would you return it from a function where I could then set another set equal to the returned set.
You can pass it the way you did, but remember that apssong like that will cause the entire set to be copied into a new set local to the function.

It is best if possible to pass by const reference:
 
void func(const set<string>& stringSet);

If you want to modify the data then just pass by normal reference:
 
void func(set<string>& stringSet);

I don't particularly recommend returning a set<string> because it will copy all the elements. However you can do that the same way you return an int:
 
set<string> func();

If you want to populate a new set it is better to pass a newly created set in as a reference rather than returning a string set:
1
2
3
4
void func(set<string>& stringSet);

set<string> my_set;
func(my_set); // populate the new set here 


Thanks a lot
Topic archived. No new replies allowed.