Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

it would be kind of someone to help with the issue:

i have a function within a class

class A
{
   void fcn1(double *p, double *hx, int m, int n, void *adata);
   void fcn2();
}

inside fcn2 i am trying to use pointer to fcn1 as follows:

A::fcn2()
{
  void (*pfcn1)(double*, double*, int, int, void*) = fcn1;
} 

and i am getting an error:

error C3867: 'A::fcn': function call missing argument list; use '&A::fcn' to create a pointer to member

it would be kind of someone to help.

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
194 views
Welcome To Ask or Share your Answers For Others

1 Answer

fcn1() is not a plain function but a member function. You can't use an ordinary function pointer to store a pointer to it, because this doesn't provide enough information: what should this be set to when the function is called?

You need to use a member function pointer instead:

void (A::*pfcn1)(double*, double*, int, int, void*) = &A::fcn1;

If you have an object a of type A, you can later call it using:

(a.*pfcn1)(&somedouble, &somedouble, 42, 69, NULL);

If you have a pointer pa to an object of type A, you can later call it using:

(pa->*pfcn1)(&somedouble, &somedouble, 42, 69, NULL);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...