Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > function pointer and member function pointer question

Reply
Thread Tools

function pointer and member function pointer question

 
 
glen stark
Guest
Posts: n/a
 
      10-10-2003
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

 
Reply With Quote
 
 
 
 
Josephine Schafer
Guest
Posts: n/a
 
      10-10-2003

"glen stark" <(E-Mail Removed)> wrote in message
news:3f86869a$(E-Mail Removed)...
> 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)


 
Reply With Quote
 
 
 
 
Ron Natalie
Guest
Posts: n/a
 
      10-10-2003

"glen stark" <(E-Mail Removed)> wrote in message news:3f86869a$(E-Mail Removed)...

> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pointer-to-member data and pointer-to-member functions and access specifiers Stephen Howe C++ 2 11-06-2012 12:32 PM
pointer to member function and pointer to constant member function Fraser Ross C++ 4 08-14-2004 06:00 PM
Function pointer member variable to non-member function Alex C++ 0 10-15-2003 05:26 PM
Function pointer member variable to non-member function slide_o_mix C++ 0 10-15-2003 03:37 PM
Passing a pointer to member function as a parameter to another member function Newsgroup - Ann C++ 5 07-30-2003 02:54 AM



Advertisments