Download MetaTrader 5

How to declare pointers in MQL5?

To add comments, please log in or register
humbertobrandao Brandao
130
humbertobrandao Brandao 2014.12.31 01:05 

I'm trying to declare pointers in .mqh files.

 In fact, I need to construct a Hashtable... 

 I was declaring like C++ code:

class HashMap {
private:
      HashEntry **table;
public:
      HashMap() {
            table = new HashEntry*[TABLE_SIZE];
            for (int i = 0; i < TABLE_SIZE; i++)
                  table[i] = NULL;
      }
 
      int get(int key) {
            int hash = (key % TABLE_SIZE);
            while (table[hash] != NULL && table[hash]->getKey() != key)
                  hash = (hash + 1) % TABLE_SIZE;
            if (table[hash] == NULL)
                  return -1;
            else
                  return table[hash]->getValue();
      }
 
      void put(int key, int value) {
            int hash = (key % TABLE_SIZE);
            while (table[hash] != NULL && table[hash]->getKey() != key)
                  hash = (hash + 1) % TABLE_SIZE;
            if (table[hash] != NULL)
                  delete table[hash];
            table[hash] = new HashEntry(key, value);
      }     
 
      ~HashMap() {
            for (int i = 0; i < TABLE_SIZE; i++)
                  if (table[i] != NULL)
                        delete table[i];
            delete[] table;
      }
};

 But, in the line

HashEntry **table;

I got the first error:

Error:
Pointer to pointer is illegal.

 In this context, I would like to know how to solve this problem in MQL5.

Any ideas?

Tks, 

Alain Verleyen
Moderator
31094
Alain Verleyen 2014.12.31 01:15  
https://www.mql5.com/en/code/11117
HashMap implementation
HashMap implementation
  • votes: 10
  • 2014.02.11
  • ydrol
  • www.mql5.com
An implementation of a HashMap in MQL4
To add comments, please log in or register