"Woodster" <mi****@127.0.0.1> wrote in message
news:MP************************@news.westnet.com.a u...
I have declared the following
std::map<std::string, std::string> myMap;
to pass myMap to functions should I be declaring functions as:
void function(std::map<std::string, std::string>);
or is there a preferred/better method of doing this?
It depends on what the function does.
Unless you need to copy the whole map when you pass it, a reference to it
would be better:
void function(std::map<std::string, std::string> &);
And if you aren't changing the map in the function, use a const reference:
void function(const std::map<std::string, std::string> &);
You can also use a typedef if you want:
typedef std::map<std::string, std::string> MyMap;
Then use MyMap everywhere you would have used std::map<std::string,
std::string>, e.g.,
void function(const MyMap &);
DW