Re: How to convert a pointer to member function type to a const member one
  Home FAQ Contact Sign in
comp.lang.c++.moderated only
 
Advanced search
POPULAR GROUPS

more...

 Up
Re: How to convert a pointer to member function type to a const member one         

Group: comp.lang.c++.moderated · Group Profile
Author: Devdatt Lad
Date: Apr 30, 2008 20:19

> What is the best way to get a type TC from a type T where
>
> T is int(foo::*)(char)
> and
> TC is int(foo::*)(char) const

These two types are completely different. A better way to understand the
meaning of these types is:

T ==> int (foo::*)(foo obj, char c)
TC ==> int (foo::*)(const foo obj, char c)

Thus, it is not the member function pointer which is const or non-const. It
is actually an argument of the member function that differs in const-ness.
This cannot be done with a static_cast or a const_cast.

You can use a reinterpret_cast to do this.

T x = &foo::abc;
TC y = reinterpret_cast(x);

but be careful when using the result of reinterpret_cast.

Hope this helps,
Devdatt

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
no comments
diggit! del.icio.us! reddit!

RELATED THREADS
SubjectArticles qty Group
Re: To convert or not to convert, that's the questioncomp.lang.clipper.visual-objects ·