For example there is a primitive entry
int Funk(bool Er,int q1,int q2,int q3)
{return 0;}
This entry declares the arguments int q1, int q2,int q3. When calculating it so happened that you need to use the algorithm of this function, but the number of parameters of the int type is already greater. The values of these parameters will be passed to the array and used directly in the program. What can be done in this case?
Well, this raises the second question how can I find out how many arguments the function has in my case four (bool Er, int q1, int q2, int q3)? How to check and find out how many parameters a function has. Please do not be rude I am certainly a valenok but I really need such properties for writing programs. Is it possible to implement any of this? Here I have a sample code.
template<class T> void Fun(T a[], size_t args...)
{}
int main()
{
int *mas1[2][2] = { {1,4},{2,6} };
int mas2[2][2][2];
Fun(*mas1, 2, 2); / /number of arguments 3
Fun (**mas2, 2, 2, 2);//number of arguments 4
}
However, this code is not from mql4. What can be done to implement this and is it possible?
laryx
1-2. If you want a function with a variable number of parameters-checks will be needed in any case. Just in the case of parameters, you check the parameters themselves, in the case of an array-you check the array.
3. This is a PLO feature. The main benefit of classes is in the connection of data and functions that process them, as well as in encapsulation – users of classes have access only to what they currently need, thereby eliminating the possibility of influencing any other application blocks. To see the benefits of OOP classes, you need to work with fairly complex data structures arranged in a hierarchy. If simple data structures are used, and the application architecture is not very developed, then there is no point in building OOP bells and whistles.
seric29
1st var. I implemented it, but the disadvantage is that there are unnecessary checks.
2nd var. here it turns out in principle everything is fine but if you declare the array globally then you have to break the if condition fill the array then go back to the logical. the if condition and then continue to finish the work is also not convenient unnecessary checks but working with a dynamic array is very convenient you can immediately access the desired size in the loop. It would be cool if you could fill a dynamic array with data without breaking the logical condition.
3y vapr. in the classes I felt boots how much I did not study them and did not understand their essence, I only realized that the SPE data combine but what is the point and how they differ from the factory function, I did not understand.
igorm
it depends on the desire to create a complex structure and the tasks set
if there is no desire or ability to make universal complex code, then use the globally described variables and in the function” with an increasing number of function arguments ” just pass a certain command that you will then analyze in the function body, and use the variables themselves from the global scope
PS: you need to understand that if all the sources in different programming languages could be ported “in 2 clicks” without losing functionality or complicating the code, then there would not be such an abundance of languages – it is simply not necessary
alexeyvik
Something like this
int Funk(bool Er,int q1,int q2,int q3)
{return 0;}
int Funk(bool Er,int q1,int q2,int q3,int q4)
{return 0;}
int Funk(bool Er,int q1,int q2,int q3,int q4,int q5)
{return 0;}
int Funk(bool Er,int q1,int q2,int q3,int q4,int q5,int q6)
{return 0;}
Then how many parameters you pass to the function when it is called, that function works. This is the simplest.
Or you can organize a class and make the overload more literate.
laryx
As I see the options are as follows:
1. Declare a function with the maximum number of parameters, setting them by default to a value that cannot be passed. Accordingly, when calling – you pass only the required number, the rest-take the default values. Inside the function, you check how many values are actually passed.
2. Pass parameters inside a dynamic array.
3. Pass parameters in a special container class that knows the number and type of parameters. Personally, I use the latter case (for transmitting parameters of various indicators), it is good because the parameters can be very different. Moreover, I pass to the function a base class-interface, where all functions for getting parameters are virtual, and their implementation already depends on a specific set of parameters required for this indicator..