C++: Access protected virtual member function via a base class
Nathan Sidwell
nathan@codesourcery.com
Thu May 25 01:49:00 GMT 2000
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
More information about the Gcc-bugs
mailing list