Function pointer for Member Function 
Author Message
 Function pointer for Member Function

I fail to declare a function pointer for the member function of a class, as
outline below:

void CBoxesDlg::TestFn(void)
{
  MessageBox ("Hello from class");

Quote:
}

void TestFn (void)
{
  AfxMessageBox ("Hello from global");

Quote:
}

void CBoxesDlg::OnDebugCallfn()
{
  void TestFn (void);  /*function declaration*/

  struct ContentFn  {
    int  index;
    void (*call_back) (void);
  };

  ContentFn Select = { 1, TestFn };

  Select.call_back ();

Quote:
}

The above code only work for the global function called by pointer.  How do
I make a call to the member function CBoxesDlg::TestFn() using this type of
pointer method?

Please help.  Thanks in advance.

--
Bob JY Sai



Sun, 06 Oct 2002 03:00:00 GMT  
 Function pointer for Member Function
  Replace

          void (*call_back) (void);

With

        void (CBoxesDlg::*call_back) (void);


Quote:
> I fail to declare a function pointer for the member function of a class,
as
> outline below:

> void CBoxesDlg::TestFn(void)
> {
>   MessageBox ("Hello from class");
> }

> void TestFn (void)
> {
>   AfxMessageBox ("Hello from global");
> }

> void CBoxesDlg::OnDebugCallfn()
> {
>   void TestFn (void);  /*function declaration*/

>   struct ContentFn  {
>     int  index;
>     void (*call_back) (void);
>   };

>   ContentFn Select = { 1, TestFn };

>   Select.call_back ();
> }

> The above code only work for the global function called by pointer.  How
do
> I make a call to the member function CBoxesDlg::TestFn() using this type
of
> pointer method?

> Please help.  Thanks in advance.

> --
> Bob JY Sai



Sun, 06 Oct 2002 03:00:00 GMT  
 Function pointer for Member Function
Thank Mark,

I can declare and define the struct now, but it give error in calling the
function.  What is the new calling syntax like?

void CBoxesDlg::OnDebugCallfn()
{
  // void TestFn (void);  /* function declaration */

  struct ContentFn  {
    int  index;
    void (CBoxesDlg::*call_back) (void);
  };

  ContentFn Select = { 1, TestFn };

  Select.call_back (); /* Error C2064: term does not evaluate */
                    /* to a function.  Error executing cl.exe */

Quote:
}

Thanks for your helps.

Bob JY Sai


Quote:
>   Replace

>           void (*call_back) (void);

> With

>         void (CBoxesDlg::*call_back) (void);



> > I fail to declare a function pointer for the member function of a class,
> as
> > outline below:

> > void CBoxesDlg::TestFn(void)
> > {
> >   MessageBox ("Hello from class");
> > }

> > void TestFn (void)
> > {
> >   AfxMessageBox ("Hello from global");
> > }

> > void CBoxesDlg::OnDebugCallfn()
> > {
> >   void TestFn (void);  /*function declaration*/

> >   struct ContentFn  {
> >     int  index;
> >     void (*call_back) (void);
> >   };

> >   ContentFn Select = { 1, TestFn };

> >   Select.call_back ();
> > }

> > The above code only work for the global function called by pointer.  How
> do
> > I make a call to the member function CBoxesDlg::TestFn() using this type
> of
> > pointer method?

> > Please help.  Thanks in advance.

> > --
> > Bob JY Sai



Mon, 07 Oct 2002 03:00:00 GMT  
 Function pointer for Member Function

  (this->*(Select.call_back))(); // see operator ->* in the MSDN

Good Luck,
Mark


Quote:
> Thank Mark,

> I can declare and define the struct now, but it give error in calling the
> function.  What is the new calling syntax like?

> void CBoxesDlg::OnDebugCallfn()
> {
>   // void TestFn (void);  /* function declaration */

>   struct ContentFn  {
>     int  index;
>     void (CBoxesDlg::*call_back) (void);
>   };

>   ContentFn Select = { 1, TestFn };

>   Select.call_back (); /* Error C2064: term does not evaluate */
>                     /* to a function.  Error executing cl.exe */
> }

> Thanks for your helps.

> Bob JY Sai



> >   Replace

> >           void (*call_back) (void);

> > With

> >         void (CBoxesDlg::*call_back) (void);



> > > I fail to declare a function pointer for the member function of a
class,
> > as
> > > outline below:

> > > void CBoxesDlg::TestFn(void)
> > > {
> > >   MessageBox ("Hello from class");
> > > }

> > > void TestFn (void)
> > > {
> > >   AfxMessageBox ("Hello from global");
> > > }

> > > void CBoxesDlg::OnDebugCallfn()
> > > {
> > >   void TestFn (void);  /*function declaration*/

> > >   struct ContentFn  {
> > >     int  index;
> > >     void (*call_back) (void);
> > >   };

> > >   ContentFn Select = { 1, TestFn };

> > >   Select.call_back ();
> > > }

> > > The above code only work for the global function called by pointer.
How
> > do
> > > I make a call to the member function CBoxesDlg::TestFn() using this
type
> > of
> > > pointer method?

> > > Please help.  Thanks in advance.

> > > --
> > > Bob JY Sai



Mon, 07 Oct 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Function Pointer for Member Function

2. Function Pointers to Member Functions

3. How to use (pointer to function), and function and pointer to (pointer to function)

4. Pointers to member functions as function arguments

5. (member) function returning pointer to functions like itself?

6. Getting pointer to non-static member function from C callback function

7. function pointer to a member function

8. Function pointer / function member

9. How to pass a member function as inetrnal function pointer argument

10. member functions as function pointers!

11. function pointer to a member function

12. member function as function pointer

 

 
Powered by phpBB® Forum Software