-
maps as reference?
hey,
I've got a function that i need to return two maps from. As i can't do it with a <code> return </code> is there a way to pass the two maps as reference parameters (like is possible with vectors or arrays) and thus make it possible to modify both in the function?
cheers every1.
Rob.
-
Since you know that references work for some types, doesn't it seem reasonable that references OUGHT to work for some other types?
In other words, if you've already tried and failed, then post some of what you tried here.
-
>I've got a function that i need to return two maps from.
Passing them by reference to the function would work just fine. Or if you need to create them locally and return them, try returning a pair:
Code:
#include <utility>
// Replace with a more suitable typedef
typedef map<string, int> maptype;
pair<maptype, maptype> foo()
{
maptype a;
maptype b;
// ...
return make_pair ( a, b );
}
Then you have both maps in an easily accessed location that suggests a relationship. Of course, if they are completely unrelated, a pair may be confusing to readers.