Hi all,
I have a structure that includes a constructor. I want to add a bunch of these
structures to an STL map (whose index is an int). If I define the map like
this:
map<int, MyStruct*myMap;
then I can add pointers to newly allocated structures like this:
myMap[index] = new MyStruct(constr uctorArguments) ;
The downside of this is that now I have a map of pointers to structures and I'm
stuck with an extra indirection whenever I access the map, which just adds a bit
of obfuscation to the code. Is there an easy way to actually declare the map
like this:
map<int, MyStructMyMap
and then add newly constructed structures (not pointers to structures) to the
map?
TIA - Bob
I have a structure that includes a constructor. I want to add a bunch of these
structures to an STL map (whose index is an int). If I define the map like
this:
map<int, MyStruct*myMap;
then I can add pointers to newly allocated structures like this:
myMap[index] = new MyStruct(constr uctorArguments) ;
The downside of this is that now I have a map of pointers to structures and I'm
stuck with an extra indirection whenever I access the map, which just adds a bit
of obfuscation to the code. Is there an easy way to actually declare the map
like this:
map<int, MyStructMyMap
and then add newly constructed structures (not pointers to structures) to the
map?
TIA - Bob
Comment