Topic: Ambiguous conversion due to private base class member


Author: "Walter W. Karas" <wkaras@ibm.net>
Date: 1998/04/05
Raw View
jkanze@otelo.ibmmail.com wrote:
>
> I'd just like a confirmation that the following program is legal:
>
>     #include <stddef.h>
>
>     class B {} ;
>     class D : public B {} ;
>
>     class BPtr { public: operator B*() ; } ;
>     class DPtr : private BPtr { public: operator D*() ; } ;
>
>     bool
>     f( DPtr p )
>     {
>         return ( p == NULL ) ;
>     }
>
> I have tried it on two compilers (VC++ and CSet++), and both declare
> ambiguous conversion in the line with the return.  IMHO, since the
> derivation is private, the compiler shouldn't see the conversion
> operator in the base class, so the conversion shouldn't be ambiguous.

Does the compiler specifically say it's converting from DPtr to BPtr?
DPtr -> B * would also be a valid implicit conversion.  Maybe

return(p == static_cast<D *>(0));

would work?
---
[ 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              ]





Author: "Matt Seitz" <mseitz@meridian-data.com>
Date: 1998/03/24
Raw View
jkanze@otelo.ibmmail.com wrote in message
<6erric$485$1@nnrp1.dejanews.com>...
>IMHO, since the
>derivation is private, the compiler shouldn't see the conversion
>operator in the base class, so the conversion shouldn't be ambiguous.

According to the standard, the compilers are right.  Section 11.4 says
  "It  should be noted that it is access to members and base classes that
  is controlled, not their visibility.  Names of members are still visi-
  ble,  and  implicit  conversions to base classes are still considered,
  when those members and base classes are inaccessible.  The interpreta-
  tion of a given construct is established without regard to access con-
  trol.  If the interpretation established  makes  use  of  inaccessible
  member names or base classes, the construct is ill-formed."

For an explanation of why this is, see THE DESIGN AND EVOLUTION OF C++,
section 2.10.
---
[ 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              ]





Author: jkanze@otelo.ibmmail.com
Date: 1998/03/19
Raw View
I'd just like a confirmation that the following program is legal:

    #include <stddef.h>

    class B {} ;
    class D : public B {} ;

    class BPtr { public: operator B*() ; } ;
    class DPtr : private BPtr { public: operator D*() ; } ;

    bool
    f( DPtr p )
    {
 return ( p == NULL ) ;
    }

I have tried it on two compilers (VC++ and CSet++), and both declare
ambiguous conversion in the line with the return.  IMHO, since the
derivation is private, the compiler shouldn't see the conversion
operator in the base class, so the conversion shouldn't be ambiguous.

Have I missed something, or did the compiler writers?

--
James Kanze    +33 (0)1 39 23 84 71    mailto: kanze@gabi-soft.fr
        +49 (0)69 66 45 33 10    mailto: jkanze@otelo.ibmmail.com
GABI Software, 22 rue Jacques-Lemercier, 78000 Versailles, France
Conseils en informatique orient   e objet --
              -- Beratung in objektorientierter Datenverarbeitung

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading



[ 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              ]