Each object gets a unique "name" (actually called ID) and then a pointer to the object is stored in a map of strings (The IDs or Keys) and then Object* But when I try to do this in the constructor of an object: ObjectMan.insert(pair<string, Object*>(ID, this));
I get an access violation error. I have tried numerous things to resolve this, but I don't know what the problem is. The debug stops in the xtree file, but I know it's the line described above that is causing the access violation.
I'm not quite good at using pointers, but I understand the basics of them. I would like to know how I would go upon storing pointers to objects in a map of pointers in the objects constructor. I have no idea why the access violation is happening, might just need to change a "*" or "&" symbol here or there.
Something you probably need to know is that, the Map is a container for an Object class, but the class I'm trying to store is an inherited class from the Base Object Class.
Also, the ObjectManager class is not a map itself, but a class based off of a map
1 2 3 4 5 6
struct ObjectManager : map<string, Object*>
{
//Functions
void renameEntry(string ID, string newID); //Renames the string associated with an object
void removeEntry(string ID); //Removes an entry of an object
};
It still gets access violation errors. I think it's because "this" is a constant and somewhere in the magical windows files it tries to edit the pointer that I pass to the map.
All I want is a map that stores pointers to Objects.
I'm not sure what's causing your problem, but don't inherit from STL containers. They don't have virtual destructors and it's much easier and clearer to treat them as black box abstractions.
Also, you should avoid doing anything in a constructor that might throw an exception, because that will leave your object in such a state that the destructor will not be called.