I want to store References to different Objects in a map, but I don't know how to define the map.
e.g:
map<string, & ObjectReferenceOfAnyKind> myList;
myList[ "keyA", stringA );
myList[ "keyBlist", vector );
myList[ "file", fileObject );
string &value = (string&) myList["keyA"];
CFile &fobj = (CFile&a开发者_运维知识库mp;) myList["file"];
Any suggestion how to solve this?
STL maps (like all STL containers) only store values belonging to a single type. So, you could use pointers to a base class or a union as the value type. Boost offers a modern discriminating union with Variant.
精彩评论