I feel like this question is basic enough to be out there somewhere, but I can't seem to be able to find an answer for it.
Suppose I have this code:
//class member function
std::map< std::string, std::string > myMap;
const std::map< std::string, std::string >& bar()
{
return myMap;
}
void myFunc( std::map< std::string, std::string >& foo1 )
{
foo1 = bar();
std::map< std::string, std::string >& foo2 = bar();
}
My understanding is that if I start using foo2, since foo2 is a reference to the same instance as what bar() returns, anything I do with foo2 will be reflected in myMap. But what about foo1? Does foo1 get a copy of myMap or does it also point to the same instance as what bar() returns? The c++ standard library says that the assignment operator for std::map will copy the elements over, but then does that mean the assignment operator is not really invoked in the declaration of foo2?
Thanks!