Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: How to conv...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 13 Topic 9564 of 9823
Post > Topic >>

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

by smolensky@[EMAIL PROTECTED] Apr 30, 2008 at 09:54 PM

On Apr 30, 12:38 pm, mcostalba <mcosta...@[EMAIL PROTECTED]
> wrote:
> Hi all,
>
>    I have a problem.
>
> 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
>
> I have tried
>
> typdef T const TC
>
> but with no success.
>

You can use reinterpret_cast or C-style cast, if this is what you are
really want. There is no automatic or const conversion from one to
another. T is a (non-const) pointer to non-const member function, TC
is a (non-const) pointer to const member function.

The reason is when member functions are translated, they are passed
this pointer as a first argument as if they had signatures:

f( foo* this, char ) and
f( foo const* this, char )

T is a pointer to function receiving foo* and TC is a pointer to
function receiving foo const*.

If you had const and non-const pointers to the same type:

typedef int(foo::* U)(char); // non-const pointer to member
typedef U const UC;    // const pointer to member

U mf;
UC cmf = &U::f;
mf = cmf;

it would work.

-Michael

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




 13 Posts in Topic:
How to convert a pointer to member function type to a const memb
mcostalba <mcostalba@[  2008-04-30 10:38:30 
Re: How to convert a pointer to member function type to a const
nickf3 <nickf3@[EMAIL   2008-04-30 17:04:17 
Re: How to convert a pointer to member function type to a const
smolensky@[EMAIL PROTECTE  2008-04-30 21:54:58 
Re: How to convert a pointer to member function type to a const
"Devdatt Lad" &  2008-04-30 21:54:37 
Re: How to convert a pointer to member function type to a const
Greg Herlihy <greghe@[  2008-04-30 22:17:24 
Re: How to convert a pointer to member function type to a const
mcostalba <mcostalba@[  2008-05-01 13:43:23 
Re: How to convert a pointer to member function type to a const
"Roman.Perepelitsa@[  2008-05-05 07:09:51 
Re: How to convert a pointer to member function type to a const
mcostalba <mcostalba@[  2008-05-06 00:57:14 
Re: How to convert a pointer to member function type to a const
"Roman.Perepelitsa@[  2008-05-06 08:21:31 
Re: How to convert a pointer to member function type to a const
mcostalba <mcostalba@[  2008-05-06 12:47:31 
Re: How to convert a pointer to member function type to a const
dizzy <dizzy@[EMAIL PR  2008-05-07 11:04:35 
Re: How to convert a pointer to member function type to a const
"Roman.Perepelitsa@[  2008-05-07 11:04:05 
Re: How to convert a pointer to member function type to a const
mcostalba <mcostalba@[  2008-05-07 18:33:58 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 1:47:44 CDT 2008.