function pointer and member function pointer question

Discussion in 'C++' started by glen stark, Oct 10, 2003.

  1. glen stark

    glen stark Guest

    Okay, I know that a function pointer and member function pointer have
    different types.

    Is it kosher to convert a member function pointer to a regurlar function
    pointer (with the same parameters)? I have a measurement class, and I'd
    like to be rather general, so store function pointers for get
    operations. Can I typecast a member fuction pointer and pass it to the
    class?

    I know the FAQ disucusses this a bit, but I can't infer the answer from
    it.

    Thanks,
    Glen
    glen stark, Oct 10, 2003
    #1
    1. Advertising

  2. "glen stark" <> wrote in message
    news:3f86869a$...
    > Okay, I know that a function pointer and member function pointer have
    > different types.
    >
    > Is it kosher to convert a member function pointer to a regurlar function
    > pointer (with the same parameters)? I have a measurement class, and I'd
    > like to be rather general, so store function pointers for get
    > operations. Can I typecast a member fuction pointer and pass it to the
    > class?


    No.
    Only pointers to _static_ member functions are type compatible with normal
    pointer-to-functions.

    --
    J.Schafer
    (Remove no_spam_ to contact by mail)
    Josephine Schafer, Oct 10, 2003
    #2
    1. Advertising

  3. glen stark

    Ron Natalie Guest

    "glen stark" <> wrote in message news:3f86869a$...

    > Is it kosher to convert a member function pointer to a regurlar function
    > pointer (with the same parameters)?


    Absolutely not. A pointer-to-member is really just a selector of a method
    within an object (an offset if you wish). It has no meaning other than when
    applied to an object via the .* or ->* operators. A regular function pointer
    can be called by itself, while a (non static) member function has to be called
    in the context of an object.
    Ron Natalie, Oct 10, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Newsgroup - Ann
    Replies:
    5
    Views:
    602
    John Carson
    Jul 30, 2003
  2. Fraser Ross
    Replies:
    4
    Views:
    1,040
    Fraser Ross
    Aug 14, 2004
  3. Stephen Howe
    Replies:
    2
    Views:
    285
    Stephen Howe
    Nov 6, 2012
  4. somenath
    Replies:
    10
    Views:
    275
    James Kanze
    Jul 2, 2013
  5. somenath
    Replies:
    2
    Views:
    155
    somenath
    Aug 29, 2013
Loading...

Share This Page