This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: C++: Access protected virtual member function via a base class
- To: yumf at ultimatech dot com
- Subject: Re: C++: Access protected virtual member function via a base class
- From: Nathan Sidwell <nathan at codesourcery dot com>
- Date: Thu, 25 May 2000 09:49:21 +0100
- CC: gcc-bugs at gcc dot gnu dot org
- Organization: CodeSourcery, LLC
- References: <200005250713.AAA19775@cisc.chasingwind.com>
Marco Man-Fai Yu wrote:
> g++ prints the following error when compiling the following code.
>
> foo.cc: In method `void Derived::Do()':
> foo.cc:8: `void Base::Do()' is protected
> Is this a bug in g++? I think it is legal to access protected member
> functions of my base class, even if it is another instantiation,
> according to Stroustrup and other C++ books.
Not a bug. see [11.2]/4 and [11.5]/1 which is a rather convoluted
bit of the standard. 11.2 would allow you access, but 11.5 denies it.
11.5 says an additional check is made for a
protected member of the base, in that the access has to be through
a pointer, reference of object of the derived class itself. In
your example, going via `q' is ok, but `p' is not.
nathan
--
Dr Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org