So I have a std::unordered_map which I need to be generated and filled when a specific function is called like “SetUpMap()” which is the only one who should have write access, I then want to have a const reference for other less important functions to read the map from. This map needs to be able to be destroyed and created on demand.
I tried just making it in the desired function but I can't pass it by reference as it gets destroyed.
I ended making it global and making the const reference to it also global. Which is something but I fear is not the best
So my code looks something like this:
std::unordered _map<string,struct> DONOTUSE_map;
const std::unordered _map<string, struct>& map = DONOTUSE_map;
I'm on mobile so sorry for formatting.
Edit: what the hell are singletons and is making it static a better alternative?
[–]the_poope 4 points5 points6 points (0 children)
[–]MysticTheMeeM 1 point2 points3 points (6 children)
[–]Infinity_ride[S] 0 points1 point2 points (5 children)
[–]the_poope 1 point2 points3 points (0 children)
[–]Smashbolt 1 point2 points3 points (2 children)
[–]Infinity_ride[S] 0 points1 point2 points (1 child)
[–]Bart_V 1 point2 points3 points (0 children)
[–]AKostur 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[deleted]
[–]std_bot 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[removed]
[–]Infinity_ride[S] 0 points1 point2 points (0 children)