You cannot store references because they are not copy constructible (and some operations will be impossible because they are not default constructible either).
You can however emulate the behavior using a pointer:
std::map<int, ClassA*> test;
It's a bit annoying because you then need to dereference twice:
std::map<int, ClassA*>::iterator it = test.begin();
it->second->foo();
but with a map it's much less confusing than with a vector or set (it would be (*it)->foo().
Finally, there are some gotchas (those of a pointer):
- You must ensure than the object pointed to will remain alive as long as you wish to use the pointer
- The default initialization of a pointer is a random value, using it cause undefined behavior
- When the pointer is thrown away, the object remains (thankfully), but it does mean you need to make it'll get destroyed at one point