How to pass a callBack function as parameter for another function? and pointers? (correct syntax plz)

To add comments, please log in or register
ivanez
47
ivanez  

I want to do this

class MyClass
{

        void func1( bool (func2)() )
        {
                if ( func2() )
                {
                  
                }
        }       

);

and this too

void func1( void *MyPointer )
{
     MyType *mt = (void*)MyPointer; 
}


But it doesn't works in MQL. 

I was reading the Data Types Reference but i found  nothing about it.

Data Types - Language Basics - MQL4 Reference Data Types - Language Basics - MQL4 Reference

https://docs.mql4.com/basis/types


Someone knows how to do it?

Data Types - Language Basics - MQL4 Reference
Data Types - Language Basics - MQL4 Reference
  • docs.mql4.com
Any program operates with data. Data can be of different types depending on their purposes. For example, integer data are used to access to array components. Price data belong to those of double precision with floating point. This is related to the fact that no special data type for price data is provided in MQL4. Data of different types are...
William Roeder
18893
William Roeder  
ivanez: Someone knows how to do it?
  1. You posted Data Types - Language Basics - MQL4 Reference. Why didn't you click on the sub-page User-defined Types?
    1. Added support for pointers to functions to simplify the arrangement of event models.
                List of changes in MetaTrader 5 Client Terminal builds - MetaTrader 4 - General - MQL5 programming forum - Page 17 ? 20 2016.04.20
    2.           Pointers to Functions - Fiscal Policy - MQL4 and MetaTrader 4 - MQL4 programming forum
    3.           Language Basics / Data Types / User-defined Types - Reference on algorithmic/automated trading language for MetaTrader 5
                User-defined Types - Data Types - Language Basics - MQL4 Reference

  2. Why did you post your MT4 question in the Root / MT5 Indicators section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

ivanez
47
ivanez  
William Roeder:
  1. You posted Data Types - Language Basics - MQL4 Reference. Why didn't you click on the sub-page User-defined Types?
    1.           Pointers to Functions - Fiscal Policy - MQL4 and MetaTrader 4 - MQL4 programming forum
    2.           Language Basics / Data Types / User-defined Types - Reference on algorithmic/automated trading language for MetaTrader 5
                User-defined Types - Data Types - Language Basics - MQL4 Reference

  2. Why did you post your MT4 question in the Root / MT5 Indicators section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

Thank you very much for your help, Mr. William. That's just what I was looking for.

I am sorry about my post in the wrong place. I'm new here and I'm a little lost. I've only been programming for two weeks at MQL and I still can not see the differences between the two versions.

I am programming in MQL4 because Metatrader 5 does not work on my computer (Windows 8.1).

I have tried to install the program from several sources always with the same result (Crash). And I've been reading that a lot of people can not make the program run properly either. 

Thank you so much !!

nicholi shen
2380
nicholi shen  
typedef int (*TFunc)(int, int);


int add(int x, int y) {
   return x + y;
}

int multiply(int x, int y) {
   return x * y;
}

int doWork(TFunc callback) {
   return callback(3, 3);
}

void OnStart(){
   Print(doWork(add));
   Print(doWork(multiply));
 
}
ivanez
47
ivanez  
nicholi shen:

Thank you so much!! 

To add comments, please log in or register