So I am trying to implement a class (whose incomplete code can be seen below). In its implementation, I want to use a static pointer to help with static operations. However, I don't know what would be the best way to delete that pointer's memory upon de-initialization (I know I can implicitly delete it). Does anyone have any have any advice?
- Questions on OOP (Object Oriented Programming)
- Trailing Stop code (using the Metaquote class)
- Questions on OOP in MQL5
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.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register