function pointer and member function pointer question

G

glen stark

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
 
J

Josephine Schafer

glen stark said:
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.
 
R

Ron Natalie

glen stark said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top