| Re: How to convert a pointer to member function type to a const member one |
|
 |
|
 |
|
 |
|
 |
Group: comp.lang.c++.moderated · Group Profile
Author: Devdatt LadDevdatt 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
|