Pointer to this function type is not supported yet.

 

I am trying to make a pointer to a method. When I try to compile it says "Pointer to this function type is not supported yet". I don't understand what the function type in this error means. Is it the return type? The method I am calling is a static function but is in a virtual child class. (the class is a filter for the built in expert signal) Would that be the reason I get the error? My code is just a copy of the comment from this post https://www.mql5.com/en/forum/172507#comment_4185703. 

To declare a pointer to a function, specify the "pointer to a function" type, for example:

typedef int (*TFunc)(int,int);

Now, TFunc is a type, and it is possible to declare the variable pointer to the function:

TFunc func_ptr;

The func_ptr variable may store the function address to declare it later:

int sub(int x,int y) { return(x-y); }
int add(int x,int y) { return(x+y); }
int neg(int x)       { return(~x);  }

func_ptr=sub;
Print(func_ptr(10,5));

func_ptr=add;
Print(func_ptr(10,5));

func_ptr=neg;           // error: neg is not of  int (int,int) type
Print(func_ptr(10));    // error: there should be two parameters

Pointers to functions can be stored and passed as parameters. You cannot get a pointer to a non-static class method.‌

 
tanner gilliland:

I am trying to make a pointer to a method. When I try to compile it says "Pointer to this function type is not supported yet". I don't understand what the function type in this error means. Is it the return type? The method I am calling is a static function but is in a virtual child class. (the class is a filter for the built in expert signal) Would that be the reason I get the error? My code is just a copy of the comment from this post https://www.mql5.com/en/forum/172507#comment_4185703. 

To declare a pointer to a function, specify the "pointer to a function" type, for example:

Now, TFunc is a type, and it is possible to declare the variable pointer to the function:

The func_ptr variable may store the function address to declare it later:

Pointers to functions can be stored and passed as parameters. You cannot get a pointer to a non-static class method.‌

Function pointers cannot point to member functions of any object. You may only use "simple functions" for function pointers.
 
Dominik Egert #:
Function pointers cannot point to member functions of any object. You may only use "simple functions" for function pointers.

Thank you.

 
tanner gilliland:

I am trying to make a pointer to a method. When I try to compile it says "Pointer to this function type is not supported yet". I don't understand what the function type in this error means. Is it the return type? The method I am calling is a static function but is in a virtual child class. (the class is a filter for the built in expert signal) Would that be the reason I get the error? My code is just a copy of the comment from this post https://www.mql5.com/en/forum/172507#comment_4185703. 

To declare a pointer to a function, specify the "pointer to a function" type, for example:

Now, TFunc is a type, and it is possible to declare the variable pointer to the function:

The func_ptr variable may store the function address to declare it later:

Pointers to functions can be stored and passed as parameters. You cannot get a pointer to a non-static class method.‌

If you really want to call a method of an object from a pointer, you can use a wrapper function with your normal parameters plus a pointer parameter to the object. Inside the wrapper you then use this to call the object method.
 
Alain Verleyen #:
If you really want to call a method of an object from a pointer, you can use a wrapper function with your normal parameters plus a pointer parameter to the object. Inside the wrapper you then use this to call the object method.
Does that have a use case? - I would assume, this should be solved by virtual functions instead of wrapping?

I mean, there is no point in doing that, as it is technically the same as using the vtable, isn't it?


 
Dominik Egert #:
Does that have a use case? - I would assume, this should be solved by virtual functions instead of wrapping?

I mean, there is no point in doing that, as it is technically the same as using the vtable, isn't it?


"Should be" ?

Sorry to do things you think should not be done

My use case with pseudo code :

class CGeneric
 {
  Environment  envX;
  //--- need to call ProcessingGenericFunction(with correct params) : NOT POSSIBLE
  Call Wrapper(envX.instance,params);
 };
//---
function Wrapper(void*ptr,Params params)
 {
   ptr.ProcessingGenericFunction(params);
 }
//---
class CBaseGenericContainer
 {
  Environment        env;
  AnyType            anyVariables;
  CGeneric           embeddedInstances[];//using env

  void               ProcessingGenericFunction(Params)
   {
    //---  Use AnyVariables and embeddedInstances
   }
 };
//---
class CSpecificContainer1 : CBaseGenericContainer
 {
  //--- define the specific action 1 
  env = Environment(1);
 };
//---
class CSpecificContainer2 : CBaseGenericContainer
 {
  //--- define the specific action 2
  env = Environment(2);
 };

This come from practice, not theory. It COULD be done otherwise without any doubt, but it's what came from my dev process.

It's simplified pseudo version, the real code is using templates additionally.

 
Alain Verleyen #:

"Should be" ?

Sorry to do things you think should not be done

My use case with pseudo code :

This come from practice, not theory. It COULD be done otherwise without any doubt, but it's what came from my dev process.

It's simplified pseudo version, the real code is using templates additionally.

No need to be sorry. Just been curious what kind of use case you were thinking of.


Reason: