Topic: Accessibility and initialization


Author: postmast.root.admi.gov@iname.com (blargg)
Date: 1999/07/19
Raw View
In article <7mv491$qbv$1@nnrp1.deja.com>, wmm@fastdial.net wrote:

> In article <37911796.74C23C62@cs.tu-berlin.de>,
>   Roman Lechtchinsky <wolfro@cs.tu-berlin.de> wrote:
> > does a virtual base class have to be accessible when it is
> > initialized, i.e. is the following code legal?

[snip code - almost identical to code I add below, except "final" is named
"Dummy"]

> There is no special dispensation for members of virtual base classes.
> Bar::Bar() does not have access to Dummy::Dummy(); the "virtual"
> keyword is completely unrelated to access control.
>
> (This question was asked and specifically addressed in issue 7 of
> the Core Language Issue List, so this is the official word of the
> Committee.)

So, this means it would be possible to make the "final" virtual base class
hack reusable?

// library

    class final {
    public:
        final() { }
    };

// user

    // can't derive from Foo
    class Foo : private virtual final {
    public:
        Foo() { } // can access final ctor
    };

    class Bar : public Foo {
    public:
        Bar() { } // can't access final ctor
    };


[ 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: wmm@fastdial.net
Date: 1999/07/21
Raw View
In article
<postmast.root.admi.gov-1907991609360001@as3-dialup-26.io.com>,
  postmast.root.admi.gov@iname.com (blargg) wrote:
>
> In article <7mv491$qbv$1@nnrp1.deja.com>, wmm@fastdial.net wrote:
>
> > In article <37911796.74C23C62@cs.tu-berlin.de>,
> >   Roman Lechtchinsky <wolfro@cs.tu-berlin.de> wrote:
> > > does a virtual base class have to be accessible when it is
> > > initialized, i.e. is the following code legal?
>
> [snip code - almost identical to code I add below, except "final" is
named
> "Dummy"]
>
> > There is no special dispensation for members of virtual base
classes.
> > Bar::Bar() does not have access to Dummy::Dummy(); the "virtual"
> > keyword is completely unrelated to access control.
> >
> > (This question was asked and specifically addressed in issue 7 of
> > the Core Language Issue List, so this is the official word of the
> > Committee.)
>
> So, this means it would be possible to make the "final" virtual base
class
> hack reusable?
>
> // library
>
>     class final {
>     public:
>         final() { }
>     };
>
> // user
>
>     // can't derive from Foo
>     class Foo : private virtual final {
>     public:
>         Foo() { } // can access final ctor
>     };
>
>     class Bar : public Foo {
>     public:
>         Bar() { } // can't access final ctor
>     };

Yes, sure -- as was pointed out elsewhere in this thread, all you
have to do is change the declaration of Bar to include "final" as
a direct base class.

I hadn't seen this trick, but when I read a mention of it, the
version I constructed mentally was something like this:

 class make_foo_final {
     make_foo_final() { } // private
     friend class foo;
 };

 class foo: virtual make_foo_final {
     // ...
 };

A shame you can't use template parameters in friend declarations,
or this would make a useful template class.

--
William M. Miller, wmm@fastdial.net
Software Emancipation Technology (www.setech.com)


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
---
[ 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: "Bill Wade" <bill.wade@stoner.com>
Date: 1999/07/21
Raw View
blargg wrote in message ...
>So, this means it would be possible to make the "final" virtual base class
>hack reusable?
>
>// library
>    class final { };
>
>// user
>    // can't derive from Foo
>    class Foo : private virtual final { };
>
>    class Bar : public Foo {
>    public:
>        Bar() { } // can't access final ctor
>    };

class Bar : public Foo, virtual final {};    // Can access final constructor
---
[ 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: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
Date: 1999/07/18
Raw View
Hi,

does a virtual base class have to be accessible when it is initialized,
i.e. is the following code legal?

class Dummy {
public:
    Dummy();
};

class Foo : virtual Dummy {
public:
 Foo() : Dummy() {}
};

class Bar : Foo {
public:
 Bar() : Foo(), Dummy() {}
};

Note that Dummy is inherited privately in Foo and thus is inaccessible
in Bar. I've always thought this is allowed and, in fact, I couldn't
find anything in the standard that would rule it out. However, some of
my compilers don't like this.

Bye

Roman


[ 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: sbnaran@localhost.localdomain (Siemel Naran)
Date: 1999/07/18
Raw View
On 18 Jul 1999 16:31:34 GMT, Roman Lechtchinsky <wolfro@cs.tu-berlin.de> wrote:

>does a virtual base class have to be accessible when it is initialized,
>i.e. is the following code legal?
>
>class Dummy {
>public:
>    Dummy();
>};
>
>class Foo : virtual Dummy {
>public:
> Foo() : Dummy() {}
>};
>
>class Bar : Foo {
>public:
> Bar() : Foo(), Dummy() {}
>};

I'm not sure if it's legal.  But you can add this
 class Bar : virtual public Dummy(), Foo {
 public:
  Bar() : Foo(), Dummy() {}
 };

--
----------------------------------
Siemel B. Naran (sbnaran@uiuc.edu)
----------------------------------
---
[ 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: wmm@fastdial.net
Date: 1999/07/19
Raw View
In article <37911796.74C23C62@cs.tu-berlin.de>,
  Roman Lechtchinsky <wolfro@cs.tu-berlin.de> wrote:
> does a virtual base class have to be accessible when it is
initialized,
> i.e. is the following code legal?
>
> class Dummy {
> public:
>     Dummy();
> };
>
> class Foo : virtual Dummy {
> public:
>  Foo() : Dummy() {}
> };
>
> class Bar : Foo {
> public:
>  Bar() : Foo(), Dummy() {}
> };
>
> Note that Dummy is inherited privately in Foo and thus is inaccessible
> in Bar. I've always thought this is allowed and, in fact, I couldn't
> find anything in the standard that would rule it out. However, some of
> my compilers don't like this.

There is no special dispensation for members of virtual base classes.
Bar::Bar() does not have access to Dummy::Dummy(); the "virtual"
keyword is completely unrelated to access control.

(This question was asked and specifically addressed in issue 7 of
the Core Language Issue List, so this is the official word of the
Committee.)

--
William M. Miller, wmm@fastdial.net
Software Emancipation Technology (www.setech.com)


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
---
[ 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              ]