Download MetaTrader 5

How to define a refrence variable ?

To add comments, please log in or register
Sign up for MQL5.community to post your Forum topic
Mohsen Khashei
616
Mohsen Khashei 2014.08.03 09:37 

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
30707
Alain Verleyen 2014.08.03 11:34  
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
616
Mohsen Khashei 2014.08.03 13:36  
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
30707
Alain Verleyen 2014.08.03 14:17  
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
616
Mohsen Khashei 2014.08.03 14:25  
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
30707
Alain Verleyen 2014.08.04 00:28  
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