From -5667519247732922545
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,4b5b1798bd044336
X-Google-Attributes: gidf78e5,public
From: JdeBP@jba.co.uk (Jonathan de Boyne Pollard)
Subject: Re: pointer to member conversion
Date: 1996/05/01
Message-ID: <4m7fm0$lm5@silver.jba.co.uk>#1/1
X-Deja-AN: 152440686
references: <3180E8D7.4352@stratus.com> <3184D6E8.1606@stratus.com> <Dqovq9.35o@research.att.com>
x-original-date: 1 May 1996 11:50:40 +0100
organization: JBA Software Products, Studley, England.
x-auth: PGPMoose V1.1 PGP comp.std.c++
reply-to: JdeBP@donor2.demon.co.uk
newsgroups: comp.std.c++
originator: austern@isolde.mti.sgi.com


Andrew Koenig (ark@research.att.com) wrote:
| In article <3184D6E8.1606@stratus.com> Vladimir Neyman <Vladimir_Neyman@stratus.com> writes:
|
| > Still, the rational of this decision eludes me. It seems that 
| > conversion from Derived C::* to Base C::* would be safe, and it 
| > seems to be in spirit of C++.
|
| But it is not safe, because a member of Derived is not necessarily
| a member of Base.  The conversion in the other direction is safe.

Time to clean your reading glasses Andrew.  (-:

The two p-t-ms are both pointers to members of the _same_class_, class C.
The question is whether a p-t-m of class C, that has type Derived, should
be freely convertible to a p-t-m of class C, that has type Base.  Currently
there is no standard conversion that allows this.

Maybe some sample source would make this clearer.

	class Base {} ;
	class Derived : public Base {} ;

	class C {
		Derived d ;
	} ;

	Derived C::*ptr_to_d_member = &C::d ;
	Base C::*ptr_to_b_member = &C::d ;	// Currently ill-formed

As I was saying before, my guess at the rationale for not allowing such a
conversion is that the p-t-ms are not pointers to objects, only pointers to
members.  One needs an object of class C before the p-t-ms can be turned
into pointers to objects.  At which time, the standard pointer conversions
can apply, and there's not a problem.

	C c_object ;
	Derived * ptr_to_d = &c_object.*ptr_to_d_member ;
	Base * ptr_to_b = ptr_to_d ;

Now it *could* be argued that p-t-m conversions of this kind are safe
(by analogy with the standard pointer conversion from `Derived *' to `Base
*' being safe), and that a `Derived C::*' should thus be freely convertible 
to a `Base C::*'.   This would give us data member object slicing.

	C c_object ;
	Base C::*ptr_to_b_member = &C::d ;	// Currently ill-formed
	Base * ptr_to_b_subobject = &c_object.*ptr_to_b_member ;	

But that argument I shall leave to someone else.  I've never desired this
myself.
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]



