Download MetaTrader 5
To add comments, please log in or register
Need mobile version of MetaTrader 5? Download it and trade!
Carl Schreiber
5954
Carl Schreiber 2015.09.05 18:11 

Hi,

am I right that we cannot have this kind of pointer structure?

struct _S{
   int i;
};
_S p, arr[];
ArrayResize(arr,5);
p = &arr[2]; // compiler error: '&' - operand expected  test_OrderArrray.mq4    

Is there another way than using a function (that requires calls by reference)?

whroeder1
13627
whroeder1 2015.09.05 19:24  
  1. p is a single _S; it is not a pointer. arr is an dynamic array of _S.
  2. &arr[2] is what you do in C++ create a pointer; taking the address of arr[2]. MQL4 doesn't have pointers (except to classes.)
  3. What are you trying to do?
Carl Schreiber
5954
Carl Schreiber 2015.09.06 07:12  
WHRoeder:
  1. p is a single _S; it is not a pointer. arr is an dynamic array of _S.
  2. &arr[2] is what you do in C++ create a pointer; taking the address of arr[2]. MQL4 doesn't have pointers (except to classes.)
  3. What are you trying to do?

add 3) I would like to have a simple access to complex structures.

add 2) I had the suspicion there are no pointers in MQl4 except to classes AND except to function calls! So I tried whether this might already (b+600) has been changed and someone has found that hidden feature.

add 1) I know, but I tried to use something others might understand what I'd like to have - due to MQL4's function calls with arrays, structs, ...

whroeder1
13627
whroeder1 2015.09.06 13:08  
You can only have pointers to classes as Structures and Classes - MQL4 Documentation says
the new operator can be applied to class objects; this operator cannot be applied to structures;
Function calls are irrelevant.
class T{
 public: 
  int v;
};
void OnStart()
  {
  T arr[3]; 
  for(int i=0; i < 3; ++i){
    arr[i].v = i;
    T* p = GetPointer(arr[i]);
    Print(p.v); // 0, 1, 2
  } 
/
To add comments, please log in or register