How to Clean up Static Pointer Attributes
- Questions on OOP (Object Oriented Programming)
- Questions on OOP in MQL5
- [ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4.
Here is a possible solution: Encapsulating the pointer in another class. In this new class, you will delete the pointer.
class Boolean_Map{ public: static string bool_arr[10]; static bool associated_truth_values[10]; static int bool_arr_size; const HashMap<string, bool>* bool_convert_map; Boolean_Map(){ this.bool_convert_map = new HashMap<string, bool>(this.bool_arr, this.associated_truth_values); } ~Boolean_Map(){delete this.bool_convert_map;} }; int Boolean_Map::bool_arr_size = 10; string Boolean_Map::bool_arr[10] = {"true", "false", "1", "0", "t", "f", "yes", "no", "y", "n"}; bool Boolean_Map::associated_truth_values[10] = {true, false, true, false, true, false, true, false, true, false}; class Boolean{ ... public: static Boolean_Map map; ... }; Boolean_Map Boolean::map();
Problem:
Other classes can create a Boolean_Map (though this might not be a bad thing). I don't think you can use a singleton implementation to get around this as this will have to include pointers or global declarations (i.e static singleton), putting us back to square one.
If anyone has a better solution feel free.