In my code I have a static class to store objects. To do stuff with inherence (casting etc) I store the objects in a map with unique_ptr
s.
std::map<std::string, std::unique_ptr<DummyClass>>Map;
The stored objects have some member variables I want to update in my code (via variable bindings) so I pass out a reference to the stored objects to being able to modify them.
DummyClass& GetObject(std::string name)
{
return *Map[name];
}
To update the members I store them in another map, in another class, to bind them to a string (I get the values via TCP/IP), something like this:
updater->registerVariable("bindingString", dummyObject.position.x);
The registerVariable
Method also takes a reference (to dummyObject.position.x
) and stores it in it's map.
std::map<std::string, std::vector<float&>> floatBindings;
But here raises the problem: I can't store references in the bindings map.
Anyone has a good idea what I could do instead? Would shared_ptr
s the way to go? But the thing is that I don't really want do use shared_ptr
s because the owner should only be the static class.