in the following code I have a small class which: Adds, Removes, Finds, and Returns all values of a T object. However I'm having troubles with the Find and getValues functions as all my attempts to return a reference or pointer has resulted in Error cannot convert _Ty2 to T*.
Here is the code:
template <typename T>
class ObjectManager {
public:
// Constructor
ObjectManager() {}
// Destructor
virtual ~ObjectManager() {}
// Add an object to the manager
void AddObject(const std::string& name, T object) {
objects_[ToLower(name)] = object;
}
// Remove an object from the manager
void RemoveObject(const std::string& name) {
objects_.erase(ToLower(name));
}
T* FindObject(std::string name) {
auto itr = objects_.find(name);
return itr != objects_.end() ? itr->second: nullptr;
}
// Get a vector of all the values in the map
std::vector<T*> GetValues() {
std::vector<T*> values;
values.reserve(objects_.size());
for (auto& object : objects_) {
values.emplace_back(object.second);
}
return values;
}
private:
// Map of objects in the manager, with string names as keys
std::map<std::string, T> objects_;
}:
and here is how i intend to use the functions:
// m_buttons = ObjectManager<ObjectManager<Button>>
for (Button* button : m_buttons.FindObject("both")->GetValues()) {
button->setClicked(false);
}