OOP, templates and macros in mql5, subtleties and uses - page 19

 
Seric29:

This macro will be void, in order to return a result from it you need an expression to be calculated, in other words you need to call a function inside it, I came to this conclusion.

Yes, try to compile this "magic-miracle" code first. Some guys here are fantasizing wildly, disconnected from reality.

 
Vict:

I don't know what the task is or whether you're digging there, but at first glance it's another approach:

So, you can replace any part of function (not necessarily array filling as it is in my case) and instantiate it as needed.

It's kind of dorky. You cast your first glance at the code and think: well, probably the array will be filled with those numbers which are passed to the function, or shuffled to that value... but it turns out...

 
Dmitry Fedoseev:

It's a bit of a doddle. You look at the code at first glance and think: well, the array will probably be filled with those numbers that are passed to the function, or shuffled to that value... but it turns out...

I'm not impressed, okay, I'm p****.

 
Vict:

You have some algorithm inside which you can put a sub-algorithm, "tweak" it so to speak, to solve a particular task. Essentially it is an analogue of virtual functions. The main thing is you asked yourself, and now you don't know why)), you have a framework, inside of which you put a loop.

I wanted to add code to this framework and have the whole thing return a result, but my framework works as void and I'm trying to figure that out. I need it to work with arrays of different dimensions.

 
Vict:

Call a function in which you pass a pointer to another function (loop body, for example)

int for3(int a, int b, int c, void(*loop)()) {
        for(int i=0; i<a; i++)
                for(int j=0; j<b; j++)
                        for(int k=0; k<c; k++) 
                                loop();
        return 4;
}


mql4 doesn't work with pointers to a function even the developers didn't do that.

Here's something I found

typedef int(*MyFuncType)(int,int);

int addition (int a, int b)
{ return (a+b); }

int subtraction (int a, int b)
{ return (a-b); }

int operation (int x, int y, MyFuncType myfunc)
{
   int g;
   g = myfunc(x,y);
   return (g);
}

int OnInit()
{
   int m,n;
   m = operation (7, 5, addition);
   n = operation (20, m, subtraction);
   Print(n);
   return(INIT_FAILED);  //just to close the expert
}
 
So not every macro can return a value, who knows?
 
Seric29:
So not every macro can return a value, who knows?

You cannot return a value from a macro at all. A macro is a replacement of one piece of code with another piece of code.

 
Dmitry Fedoseev:

You cannot return a value from a macro at all. A macro is a replacement of one piece of code with another piece of code.

I see, thank you for your clear and correct answer.

 
Well not quite right, the macro can be expanded into a ternary operator?: or comma operator (not in µl) from which a value can be returned.
 
Vict:
Well not really true, macro can be expanded into ternary operator?: or comma operator (not in µl) from which you can return value.

In C++ ternary operators are more developed, if the condition is true you can perform multiple actions and mql4 as before close access to memory and at least for 10 years the developers have not made significant changes and not created noteworthy functions (there are only functions that work with colours and text and nothing else - just stupidity).