Code:
using SpecialEventDataMap = std::map<CString, SPECIAL_EVENT_S>;
SpecialEventDataMap& CMeetingScheduleAssistantApp::GetEventsListMap() noexcept
{
return m_mapSpecialEvents;
}
I have seen questions like this (I'm trying to pass a C++ map by reference to a function and iterate through it but I cannot compile the code) but I don't want to pass the map as a reference to a function.
I was tryng to write a function that would return a reference to the map as above. Whilst it complied the application did not behave as I expected. For example, adding a entry to the map in another class did not add it as an entry in the master class.
I realize I could possibly passs a pointer to the map instead but wanted to use reference. In the end I have decided to treat the above function as a kind of "read only" function to access the map. Any entries that need to be added of deleted are done on the master map via public methods in the parent class.
Is it not possible to return a reference to the map? Or is this a bad idea?
To clarify:
The map is held in the app class. And current I have added public methods to add, modify, delete items from the map. This works. But originally I way attempting to obtain a reference to the map, from within the other classes and then directly adding them to that referenced map.
The way I have it now is actually better as I only have a handful of methods to manage the map. But I am curious as to why my approach to use a referenced map failed.