>Number: 6675 >Category: c++ >Synopsis: C++: derived class cannot acccess protected members of base class >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: rejects-legal >Submitter-Id: net >Arrival-Date: Thu May 16 05:46:04 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Thomas Koeller >Release: 3.0.4 >Organization: >Environment: System: Linux sarkovy.koeller.dyndns.org 2.4.18 #3 Sam Mär 23 01:29:53 CET 2002 i686 unknown Architecture: i686 host: i686-pc-linux-gnu build: i686-pc-linux-gnu target: i686-pc-linux-gnu configured with: /home/thomas/src/gnu/gcc-3.0.4/configure --prefix=/opt/gcc-v3 --enable-shared --with-gnu-as --with-gnu-ld --enable-threads=posix --enable-languages=c,c++ --with-system-zlib >Description: The program below does not compile, although it is legal. Since class 'Derived' is derived from 'Base' and consequently should be granted access to its protected members, the compiler complains about member 'X' being protected. class Base { protected: int X; }; class Derived : public Base { public: int Get(void) const; int Get(const Base & cl) const; }; int Derived::Get(void) const { return X; } int Derived::Get(const Base & cl) const { return cl.X; } >How-To-Repeat: Compile the program above. >Fix: Workaround: make base class member public >Release-Note: >Audit-Trail: >Unformatted: