Topic: HIDDEN CONSTRUCTOR


Author: Srinivas Vobilisetti <Srinivas.Vobilisetti@mci.com>
Date: 1997/07/25
Raw View
Is it allowed to create an instance of base class (Base) in the derived
class (Derived, which publicly derived from Base) member function when
the base class constructor is protected?

note: base class (Base) do not have any public constructors.

My DEC OSF1 C++ compiler allows while RS6000 C++ compiler don't.

If allowed, isn't it against the very definition of protected access?
According to DWP96,

[11] protected; that is, its name can be used only by members functions,
static member functions and friends of the class in which it is declared
and by member functions, static member functions and friends of the
classes derived from this class.

[11.5] protected member access; When a friend or a member function of a
derived class references a protected nonstatic member of a base class,
an access check applies in addition to those described earlier in this
clause (I guess it mean [11] quoted above). Except when forming a
pointer to member(5.3.1), the access must be through a pointer to,
reference to, or object of the derived class itself (or any class
derived from that class) (5.2.5). If the access is to form a pointer to
member, the nest-name-specifier shall name the derived class (or any
class derived from that class).

Thanks,
Srinivas
---
[ 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
]

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





Author: Srinivas Vobilisetti <Srinivas.Vobilisetti@mci.com>
Date: 1997/07/25
Raw View
Is it allowed to create an instance of base class (Base) in the derived
class (Derived, which publicly derived from Base) member function when
the base class constructor is protected?

note: base class (Base) do not have any public constructors.

My DEC OSF1 C++ compiler allows while RS6000 C++ compiler don't.

If allowed, isn't it against the very definition of protected access?
According to DWP96,

[11] protected; that is, its name can be used only by members functions,
static member functions and friends of the class in which it is declared
and by member functions, static member functions and friends of the
classes derived from this class.

[11.5] protected member access; When a friend or a member function of a
derived class references a protected nonstatic member of a base class,
an access check applies in addition to those described earlier in this
clause (I guess it mean [11] quoted above). Except when forming a
pointer to member(5.3.1), the access must be through a pointer to,
reference to, or object of the derived class itself (or any class
derived from that class) (5.2.5). If the access is to form a pointer to
member, the nest-name-specifier shall name the derived class (or any
class derived from that class).

Thanks,
Srinivas


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





Author: David Vandevoorde <daveed@vandevoorde.com>
Date: 1997/07/28
Raw View
Srinivas Vobilisetti wrote:
>
> Is it allowed to create an instance of base class (Base) in the
> derived class (Derived, which publicly derived from Base) member
> function when the base class constructor is protected?
>
> note: base class (Base) do not have any public constructors.

I believe not (for the reasons you state).

> [11.5] [...] Except when forming a pointer to member(5.3.1), the
> access must be through a pointer to, reference to, or object of
> the derived class itself (or any class derived from that class)
> (5.2.5). If the access is to form a pointer to member, the
> nest-name-specifier shall name the derived class (or any class
> derived from that class).

... and I don't think there no syntax to do something like that
for the invocation of the constructor.

OTOH, constructors do not have names and I believe the WP
says somewhere that access protection only applies to names
;-)

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