Topic: Why no implicit member pointer conversion?


Author: Valentin Bonnard <bonnardv@pratique.fr>
Date: 1999/01/17
Raw View
John Potter wrote:

> struct B { int b; };
> struct D : B { int d; };
> struct F { B fb; D fd; };
>
> B b;
> D d;
> F f;

> B F::* fbp(&F::fd);            // Builder rejects, egcs accepts

> Hopefully someone knowledgable will give a better answer to the question

not me !

> of why the conversion you want is not listed in chapter 4.  If nothing
> happens, reword the question and post to comp.std.c++.

This conversion is at the same time type safe and
implementable: a pointer to member is an offset (and
perhaps other informations), so you just have to apply
the delta between B and D.

Also the cast in the reversed direction should be allowed
as a static_cast<D F::*> (B F::*).

I have never understoud the reasons (if there are any)
why it isn't allowed.

--

Valentin Bonnard                mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://pages.pratique.fr/~bonnardv/

      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]