pointing to a member function/method within another function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • uli

    pointing to a member function/method within another function

    Hi all,
    I've learned native C and I'm trying to write now in C++. I want to use a
    simple routine from the "Numerical Recipes in C" for using a Newton-Raphson
    Method within my c++ class. The Newton-Raphson function for finding roots is
    called:
    float rtsafe(void (*funcd)(float, float *, float *), float x1, float x2,
    float xacc)

    'funcd' is the pointer to an external function as common in C. But since I
    want to use it with a member function of my class for computing its roots, I
    think I can't do that, because member functions are adressed relative to my
    class.

    Could anyone please give me some hints what I have to do, so that I can use
    an external function like this and give it member functions for computation.
    (Please apologise my bad style talking about coding...)

    Thanx a lot,
    uli


    --
    For reply remove NOSPAM_ from email-adress



  • John Harrison

    #2
    Re: pointing to a member function/method within another function


    "uli" <NOSPAM_uvb@nur fuerspam.de> wrote in message
    news:c7vbkv$pi6 $1@newssrv.muc. infineon.com...[color=blue]
    > Hi all,
    > I've learned native C and I'm trying to write now in C++. I want to use a
    > simple routine from the "Numerical Recipes in C" for using a[/color]
    Newton-Raphson[color=blue]
    > Method within my c++ class. The Newton-Raphson function for finding roots[/color]
    is[color=blue]
    > called:
    > float rtsafe(void (*funcd)(float, float *, float *), float x1, float[/color]
    x2,[color=blue]
    > float xacc)
    >
    > 'funcd' is the pointer to an external function as common in C. But since I
    > want to use it with a member function of my class for computing its roots,[/color]
    I[color=blue]
    > think I can't do that, because member functions are adressed relative to[/color]
    my[color=blue]
    > class.
    >
    > Could anyone please give me some hints what I have to do, so that I can[/color]
    use[color=blue]
    > an external function like this and give it member functions for[/color]
    computation.[color=blue]
    > (Please apologise my bad style talking about coding...)
    >[/color]

    Hopefully this gives the idea.

    float rtsafe(MyClass* my_class, void (MyClass::*func d)(float, float *,
    float *), float x1, float x2, float xacc)
    {
    (my_class->*funcd)(a, b, c);
    }

    john


    Comment

    • Karl Heinz Buchegger

      #3
      Re: pointing to a member function/method within another function

      uli wrote:[color=blue]
      >
      > Hi all,
      > Could anyone please give me some hints what I have to do, so that I can use
      > an external function like this and give it member functions for computation.
      > (Please apologise my bad style talking about coding...)[/color]

      Check the FAQ




      --
      Karl Heinz Buchegger
      kbuchegg@gascad .at

      Comment

      • uli

        #4
        Re: pointing to a member function/method within another function

        Thank you a lot for your quick responses. I think that are the Infos I
        need...
        uli

        --
        For reply remove NOSPAM_ from email-adress


        Comment

        Working...