looking for confirmation ..

Back to topics list To post a new topic, please log in or register
avatar
2018
gooly 2015.09.05 20: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)?



avatar
13012
WHRoeder 2015.09.05 21: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?
avatar
2018
gooly 2015.09.06 09: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, ...

avatar
13012
WHRoeder 2015.09.06 15: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
  } 

Back to topics list  

To add comments, please log in or register