Download MetaTrader 5

Passing Array as a function input argument

To add comments, please log in or register
They are already making profit from their signals. Publish your signal and join them!
Vlaser91
53
Vlaser91 2015.09.14 20:02 

Hi Guys,

I am writing a simple loop through array elements as a .dll.

Using

#import "Path"

as usual but I am unsure as to hoe to declare the function and then call it. I am using:

declaration:

int arraytest(int a, int b[]);
#import


Call in an Alert whatever this function returns:

Alert(arraytest(5,cc[]));

This doesn't compile as it is throwing reference errors on b[].

Have you got any ideas?

Thank you so much for you help and interest.



dsds

whroeder1
14480
whroeder1 2015.09.14 20:17  
Arrays must be passed by reference, not value.
Vlaser91
53
Vlaser91 2015.09.14 20:21  
WHRoeder:
Arrays must be passed by reference, not value.
Thanks. Could you kindly provide an example?
whroeder1
14480
whroeder1 2015.09.14 21:19  
Zirkon
122
Zirkon 2015.09.15 17:18  
Vlaser91
53
Vlaser91 2015.09.15 18:27  

Can I get some help here guys please, so I do #import the relevant .dll and then before closing the #import statement I refer to my function as

int arraytest(int a, int & b);

Then somewhere along the code I have defined the following array:

int cc[5] = { 1, 2, 3, 4, 5 };


and try to pass it as argument in the function in the following way:

Alert(arraytest(5,cc[]));


That throws a compilation error '] expression expected'

Any ideas?

Thanks

whroeder1
14480
whroeder1 2015.09.15 18:55  
Alert(arraytest(5,cc[]));

You have to pass variables. cc[] is not a variable name.

Zirkon
122
Zirkon 2015.09.15 19:04  
Vlaser91:

Can I get some help here guys please, so I do #import the relevant .dll and then before closing the #import statement I refer to my function as

Then somewhere along the code I have defined the following array:


and try to pass it as argument in the function in the following way:


That throws a compilation error '] expression expected'

Any ideas?

Thanks


Alert(arraytest(5,cc));
Vlaser91
53
Vlaser91 2015.09.15 19:42  
zirkoner:

Thanks, what I am getting is " 'cc' parameter conversion not allowed." during compile!
Vlaser91
53
Vlaser91 2015.09.15 19:42  
WHRoeder:

You have to pass variables. cc[] is not a variable name.

How do you think I should address this?
whroeder1
14480
whroeder1 2015.09.16 00:05  
int arraytest(int a, int & b);
pass what the function expects.
12
To add comments, please log in or register