+8  A: 

You cannot store references. References are just aliases to another variable.

The map needs a copy of the string to store:

map<pair<string, string>, string> m;

The reason you are getting that particular error is because somewhere in map, it's going to do an operation on the mapped_type which in your case is string&. One of those operations (like in operator[], for example) will return a reference to the mapped_type:

mapped_type& operator[](const key_type&)

Which, with your mapped_type, would be:

string&& operator[](const key_type& _Keyval)

And you cannot have a reference to a reference:

Standard 8.3.4:

There shall be no references to references, no arrays of references, and no pointers to references.


On a side note, I would recommend you use typedef's so your code is easier to read:

int main()
{
    typedef pair<string, string> StringPair;
    typedef map<StringPair, string> StringPairMap;

    string test;

    StringPair p("Foo","Bar");
    StringPairMap m;
    m[make_pair("aa","bb")] = test;

   return 0;

}

GMan
+1  A: 

You cannot use references as the val, due to how the template is built. You could also use pointer instead.

Junier
+2  A: 

You can use boost::reference_wrapper to store references in STL containers. Here is your example modified (not tested, and definitely not very well written, just illustrates a point)

#include <map>     
#include<iostream>
#include<string>   
#include <boost/ref.hpp>



int main()
{
   typedef std::pair< std::string, std::string> PairType;
   typedef std::map< PairType, boost::reference_wrapper<std::string> > MapType;
   std::string test = "Hello there!!";
   MapType m;
   PairType pp =  std::make_pair("aa","bb");
   m.insert(std::make_pair(pp , boost::ref(test) ) );

   MapType::iterator it (m.find( pp ) );
   if(it != m.end())
   {
       std::cout << it->second.get() << std::endl;
   }

   //change test
   test = "I am different now";
   std::cout << it->second.get() << std::endl;

   return 0;
}
navigator
that's nice... sucks that i cannot use boost :(