Download MetaTrader 5

How to define a refrence variable ?

To add comments, please log in or register
Mohsen Khashei
654
Mohsen Khashei  

Hi I have a question may be so simple but i have problem :

I want to access some variable by refrence . 

suppose we have a class :

class CLayer{
...
}
and a class 
class CNetwork{
private:
CLayer *m_layers[];
public:
....
void getout(double val);
}
void CNetwork::getout(double val)
{
....
unsigned layers=ArraySize(m_layers);
CLayer &layer=m_layers[layers-1];
....
}

 but for the last line of code i get this errors :

'&' - reference cannot used     Network.mqh     105     17
'=' - object required           Network.mqh     105     30

 whats my mistake ?

Alain Verleyen
Moderator
32028
Alain Verleyen  
pumper:

Hi I have a question may be so simple but i have problem :

I want to access some variable by reference . 

suppose we have a class :

 but for the last line of code i get this errors :

 what's my mistake ?

Where in the documentation did you see you can define a reference variable ? You can't.

Please read mql5 documentation, and don't try to use other language statement with mql5 compiler.

Mohsen Khashei
654
Mohsen Khashei  
angevoyageur:

Where in the documentation did you see you can define a reference variable ? You can't.

Please read mql5 documentation, and don't try to use other language statement with mql5 compiler.

in docs only mentioned about passing by refrence to function.but nowhere found anything else.not mentioned about it.is this means we can't use it every where else ?
Alain Verleyen
Moderator
32028
Alain Verleyen  
pumper:
in docs only mentioned about passing by refrence to function.but nowhere found anything else.not mentioned about it.is this means we can't use it every where else ?
Exactly. You can't.
Mohsen Khashei
654
Mohsen Khashei  
angevoyageur:
Exactly. You can't.

Is it legal to use pointers in such a case ?

i mean :

CLayer *layer=m_layers[layers-1];

 returns no error and is a pointer to that element.

Alain Verleyen
Moderator
32028
Alain Verleyen  
pumper:

Is it legal to use pointers in such a case ?

i mean :

 returns no error and is a pointer to that element.

Of course.
To add comments, please log in or register